Skip to main content

Utility collection for development with SQLalchemy ORM.

Project description

Read The Docs build Release PyPI downloads count MIT License Python version support GitHub continuous integration codecov.io status for master branch

Utility collection for development with SQLAlchemy 1.4 / 2.0 ORM.

Documentation

https://sqlalchemy-things.readthedocs.io

Installation

Installing sqlalchemy-things with pip:

pip install sqlalchemy-things

Examples

Single table inheritance

from sqlalchemy_things.declarative import (
    IntegerPrimaryKeyMixin,
    PolymorphicMixin,
)

metadata = sa.MetaData()
Base = orm.declarative_base(metadata=metadata)


class Parent(Base, IntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = 'single_table'


class ChildA(Parent):
    __mapper_args__ = {'polymorphic_identity': 'child_a'}
    some_field = sa.Column(sa.String(255))


class ChildB(Parent):
    __mapper_args__ = {'polymorphic_identity': 'child_b'}
    other_filed = sa.Column(sa.String(127))

Joined table inheritance with cascade primary key mixins

from sqlalchemy_things.declarative import (
    CascadeIntegerPrimaryKeyMixin,
    PolymorphicMixin,
)

metadata = sa.MetaData()
Base = orm.declarative_base(metadata=metadata)


class Parent(Base, CascadeIntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = 'cascade_pk_parent_table'


class ChildA(Parent):
    __tablename__ = 'cascade_pk_child_table_a'
    __mapper_args__ = {'polymorphic_identity': 'child_a'}
    some_field = sa.Column(sa.String(255))


class ChildB(Parent):
    __tablename__ = 'cascade_pk_child_table_b'
    __mapper_args__ = {'polymorphic_identity': 'child_b'}
    some_field = sa.Column(sa.String(127))

Joined table inheritance with simple primary key mixins

from sqlalchemy_things.declarative import (
    IntegerPrimaryKeyMixin,
    ParentPrimaryKeyMixin,
    PolymorphicMixin,
)

metadata = sa.MetaData()
Base = orm.declarative_base(metadata=metadata)


class Parent(Base, IntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = 'inherited_pk_parent_table'


class ChildA(ParentPrimaryKeyMixin, Parent):
    __tablename__ = 'inherited_pk_child_table_a'
    __mapper_args__ = {'polymorphic_identity': 'child_a'}
    some_field = sa.Column(sa.String(255))


class ChildB(ParentPrimaryKeyMixin, Parent):
    __tablename__ = 'inherited_pk_child_table_b'
    __mapper_args__ = {'polymorphic_identity': 'child_b'}
    some_field = sa.Column(sa.String(127))

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

sqlalchemy-things-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_things-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-things-0.1.1.tar.gz.

File metadata

  • Download URL: sqlalchemy-things-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.5 Linux/5.4.0-77-generic

File hashes

Hashes for sqlalchemy-things-0.1.1.tar.gz
Algorithm Hash digest
SHA256 21d931340435616460c48b91c8577e4f5ff26832ae08fc8bd6b599b7725c0262
MD5 55292c6a2764ae41c412d632b53c9c57
BLAKE2b-256 f139cc3785b3237d9ead0111ec1ce78eb813d52c944ea3d94e5f4e11a889f3d4

See more details on using hashes here.

File details

Details for the file sqlalchemy_things-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_things-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.5 Linux/5.4.0-77-generic

File hashes

Hashes for sqlalchemy_things-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4116a2d3f0438cd1cf746a13a3154e3bc9e86c917d0a76f38667f309ebbe6c96
MD5 39229a6c3a559fe4cbdece52793f2790
BLAKE2b-256 94fdfda52d940fbba49657c0f420d5d61134916f8b326fc74f678e9029546033

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