Utility collection for development with SQLAlchemy 2.0 ORM.
Documentation
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))
Release files for sqlalchemy-things 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy_things-1.2.0.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_things-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.3 kB
Release files / sqlalchemy_things-1.2.0.tar.gz
| Download URL | sqlalchemy_things-1.2.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e969d53744184a4e851dbe66bd9fc87d8e524dfbfc7e29ae370280a3588724a1
|
|
BLAKE2b-256 checksum How to use checksums |
29ab049b4942848b686ad2fad7851eac7595e8e9e1ea7e95f568971f5ca6440a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-90-generic
|
Release files / sqlalchemy_things-1.2.0-py3-none-any.whl
| Download URL | sqlalchemy_things-1.2.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77a683393e7c2b8b3f7db13ca638405e147992419d4771a9ef9f1e435135098f
|
|
BLAKE2b-256 checksum How to use checksums |
df6854917e8031ad6402515ad666c674bff81bcd8dd7c4726d61926e5e66129c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-90-generic
|