Skip to main content

Utility collection for development with SQLalchemy ORM.

Project description

Read The Docs build Release MIT License Python version support PyPI downloads count 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-1.0.0.tar.gz (6.9 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-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_things-1.0.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_things-1.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-44-generic

File hashes

Hashes for sqlalchemy_things-1.0.0.tar.gz
Algorithm Hash digest
SHA256 64f37140bbbfc53b5786336e615d24dfe6bf756b2711a0f7505697f49134f49c
MD5 9ddd8e1e3b9c0d85816eb8134dee8dc3
BLAKE2b-256 de1960c9ed923641541ae5579db848f06680339a08ac0cfd244b80c243929744

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlalchemy_things-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-44-generic

File hashes

Hashes for sqlalchemy_things-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7099030d0154e904f232b8339ed27e003e3d184ff0b769674ab6017352d77d9a
MD5 5bc7e56a379f70082b7bc75540121248
BLAKE2b-256 76e8a78a82d003a7d77d778b21e8671e00676eac41460dab268da78243c8c3af

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