Utility collection for development with SQLalchemy ORM.
Project description
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))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlalchemy_things-1.0.2.tar.gz
.
File metadata
- Download URL: sqlalchemy_things-1.0.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d16eaa16db536a5368b9af1576b89764f3e04ad4f3ee121665d43ae73860e433 |
|
MD5 | 3c17fc22bf156ca65ed2feda4a4ba5b8 |
|
BLAKE2b-256 | 2cda1535a8c8edfcbbec9d1073f6d37069267faa5a50101696c23987d1b80d8b |
File details
Details for the file sqlalchemy_things-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_things-1.0.2-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-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74e140bc1c2d59cb433f3545e14967eb1e97317388d6ca331af904ca81e2de90 |
|
MD5 | 29a9ea0ac3a8e898aac6630efc0b0e1f |
|
BLAKE2b-256 | e42bc59f7b1938f191af358756433ab264067b9698358fb12034009286afaa33 |