Utility collection for development with SQLalchemy ORM.
Project description
Utility collection for development with SQLAlchemy 1.4 / 2.0 ORM.
Documentation
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy-things-0.6.0.tar.gz.
File metadata
- Download URL: sqlalchemy-things-0.6.0.tar.gz
- Upload date:
- Size: 7.1 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16f4603f2a4c7a863811440258df9660461b59e190dc000ce76942b5d3582c8
|
|
| MD5 |
08a08a608ed9b32979daa455ddb2bd0a
|
|
| BLAKE2b-256 |
55dce585b2ffb3b1fd50e74d10248cbcfe5329158f19ce13b228ddeca5cb8d57
|
File details
Details for the file sqlalchemy_things-0.6.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_things-0.6.0-py3-none-any.whl
- Upload date:
- Size: 7.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebd9f2e7531a08fd7391cfe2f703d55211b2bf3586940078fdc00d089399df5c
|
|
| MD5 |
fd364a106fa3a70ccbff30100f62837e
|
|
| BLAKE2b-256 |
cdd3a94ba224f782bf37595e2b790a769e235910fc30b102a5cb157f002acaaa
|