EnORM
EnORM---EnDATA Object Relational Mapper.
Features
- Model Definition:
- Define database tables using Python classes.
- Support for primary keys, foreign keys, constraints, and default values.
- Type System:
- Use Python-native types for columns with support for custom SQL-compatible types.
- Full support for PostgreSQL, MySQL, SQLite, Oracle, and SQL Server backends with in-house types.
- Query Building:
- Pythonic API for constructing queries.
- Filtering, joining, grouping, ordering, and aggregation.
- Ability to use Python expressions directly in queries.
- Subquerying:
- Full support for subqueries as nested or derived tables.
- Essential for advanced query composition and reusable query fragments.
- Relationships:
- Define one-to-many and many-to-many relationships.
- Cascading updates and deletes for referential integrity.
- Transactions:
- Transaction management with commit and rollback control.
- Database Session:
- Manage database interactions with a session.
- Context manager support for secure and efficient operations.
- Connection Pooling:
- Thread-safe connection management with pooling for performance.
- Schema Management:
- Automatic SQL generation for table creation.
- Custom Functions and Aggregates:
- Built-in support for SQL functions and aggregates, extensible for complex operations.
- Data Validation:
- Automatic enforcement of field types and constraints during record creation and updates.
- Custom Exceptions:
- Comprehensive exceptions for debugging and error reporting.
Installation
EnORM is a PyPI-indexed library. You can install it by running:
pip install EnORM
EnORM supports Python 3.10+.
Example Usage
from EnORM import CASCADE, Column, DBEngine, DBSession, Float, ForeignKey, Integer, Model, Serial, String
class Company(Model):
__table__ = "companies"
id = Column(Serial, primary_key=True)
name = Column(String, nullable=False)
country = Column(String, 40)
class Employee(Model):
id = Column(Serial, primary_key=True)
full_name = Column(String, 100, nullable=False)
salary = Column(Float)
age = Column(Integer)
role = Column(String, 20, default="entry")
company_id = Column(Serial, None, ForeignKey(Company, reverse_name="employees", on_delete=CASCADE))
eng = DBEngine("postgresql://user:secret@localhost:5432/my_db", pool_size=64)
with DBSession(eng) as session:
the_company = session.query(Company).filter(Company.country == "United Kingdom").first()
new_employee = Employee(full_name="Nima Bavari Goudarzi", salary=64320.00, role="engineer", company_id=the_company.id)
session.add(new_employee)
sharks = session.query(Employee, Employee.full_name, Employee.company_id).filter(Employee.salary > 90000.00).all()
Documentation
See full documentation.
Dev Scripts
Set Up Dev Environment
Run:
make set_dev_env
to set up the dev environment.
This sets:
- git pre-commit hook
If you intend to touch the code, set up dev environment first.
Linting and Formatting
Run:
make cleanup
to run linting, formatting, typechecking, and automatically updating the documentation.
Testing
Run:
make test
to start the tests.
Metadata
Release files for EnORM 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| enorm-1.2.2.tar.gz | 34.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| enorm-1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 69.5 kB
Release files / enorm-1.2.2.tar.gz
| Download URL | enorm-1.2.2.tar.gz |
|---|---|
| Size | 34.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53e5baf7679973fbef3b17e6b87d59fb893b285cddd5315638bc7ef5617e28b3
|
|
BLAKE2b-256 checksum How to use checksums |
37e7f3b7523edafedc429b8becfaedaca087260df9d43ff9c17c8b943e6e810e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|
Release files / enorm-1.2.2-py3-none-any.whl
| Download URL | enorm-1.2.2-py3-none-any.whl |
|---|---|
| Size | 34.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d44944abc4d7ad5fdf1c8f10d8b16d3f78b2d0ea9cd73e404f30c1b02fcd0ba5
|
|
BLAKE2b-256 checksum How to use checksums |
20e940fda5ad1fd0581c84c80b3be458124f28c2e68f9f94a3851061c9063f89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|