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

Utility collection for development with SQLAlchemy 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 import orm
from sqlalchemy_things.declarative import (
    IntegerPrimaryKeyMixin,
    PolymorphicMixin,
)

class Base(orm.DeclarativeBase): ...


class ParentA(Base, IntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = "single_table"


class ChildA1(ParentA):
    __mapper_args__ = {"polymorphic_identity": "child_a1"}
    some_field = sa.Column(sa.String(255))


class ChildA2(ParentA):
    __mapper_args__ = {"polymorphic_identity": "child_a2"}
    other_filed = sa.Column(sa.String(127))

Joined table inheritance with cascade primary key mixins

from sqlalchemy import orm
from sqlalchemy_things.declarative import (
    CascadeIntegerPrimaryKeyMixin,
    PolymorphicMixin,
)

class Base(orm.DeclarativeBase): ...


class ParentB(Base, CascadeIntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = "parent_b"


class ChildB1(ParentB):
    __tablename__ = "child_b1"
    __mapper_args__ = {"polymorphic_identity": "child_b1"}
    some_field = sa.Column(sa.String(255))


class ChildB2(ParentB):
    __tablename__ = "child_b2"
    __mapper_args__ = {"polymorphic_identity": "child_b2"}
    some_field = sa.Column(sa.String(127))

Joined table inheritance with simple primary key mixins

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

class Base(orm.DeclarativeBase): ...


class ParentC(Base, IntegerPrimaryKeyMixin, PolymorphicMixin):
    __tablename__ = "parent_c"


class ChildC1(ParentPrimaryKeyMixin, ParentC):
    __tablename__ = "child_c1"
    __mapper_args__ = {"polymorphic_identity": "child_c1"}
    some_field = sa.Column(sa.String(255))


class ChildC2(ParentPrimaryKeyMixin, ParentC):
    __tablename__ = "child_c2"
    __mapper_args__ = {"polymorphic_identity": "child_c2"}
    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.1.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.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sqlalchemy_things-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0b1601b4f1c1259f2a3fa425e8bf1b1f962438f597921e4b021e587348312b89
MD5 2bdb5759b28d6328259dbab59f28ce22
BLAKE2b-256 3b5a82c8b56800b0e7ac7b0f1ae06821b18b44f3aef64f44d8fc57bbba042956

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for sqlalchemy_things-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 521698cd3bd93dcedc9c5e268c830b8898a7e4b2ceddfb84ec5f8f8b893c2729
MD5 085da8c8b39f0c24154fc78313af942f
BLAKE2b-256 441c15475e2bb32d83c82c2e9ce2479a2d00e8fc26be3328561e6756079eca8c

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