Skip to main content

EnORM—EnDATA Object Relational Mapper.

Project description

EnORM

PyPI Version PyPI Downloads License Dependencies GitHub Stars

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enorm-1.2.2.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

enorm-1.2.2-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file enorm-1.2.2.tar.gz.

File metadata

  • Download URL: enorm-1.2.2.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for enorm-1.2.2.tar.gz
Algorithm Hash digest
SHA256 53e5baf7679973fbef3b17e6b87d59fb893b285cddd5315638bc7ef5617e28b3
MD5 0693df4f33e1efb1e793b417c5739acf
BLAKE2b-256 37e7f3b7523edafedc429b8becfaedaca087260df9d43ff9c17c8b943e6e810e

See more details on using hashes here.

File details

Details for the file enorm-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: enorm-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for enorm-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d44944abc4d7ad5fdf1c8f10d8b16d3f78b2d0ea9cd73e404f30c1b02fcd0ba5
MD5 00840add449b92707695809ffd4ce510
BLAKE2b-256 20e940fda5ad1fd0581c84c80b3be458124f28c2e68f9f94a3851061c9063f89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page