An extension to SQLAlchemy to treat aggregated columns and clauses as Models
Project description
sqlalchemy_bundle_model
An extension to SQLAlchemy to treat aggregated columns and clauses as Models
usage
>>> from sqlalchemy_bundle_model import BundleModel
>>> class User(DeclarativeBase):
... __tablename__ = "users"
... id = Column(BigInteger, primary_key=True)
... name = Column(Text, nullable=False)
... group_id = Column(ForeignKey("groups.id"), nullable=False)
...
... group = relationship("Group")
...
>>> class Group(DeclarativeBase):
... __tablename__ = "groups"
... id = Column(BigInteger, primary_key=True)
... name = Column(Text, nullable=False)
...
>>> class GroupUser(BundleModel):
... id = col(int, User.id)
... name = col(str, User.name)
... group_name = col(str, Group.name)
...
... @staticmethod
... def join(_query: Query):
... return _query.join(User.group)
...
>>> session = session_cls()
>>> query = session.query(GroupUser)
>>> query = GroupUser.join(query)
>>> result = query.first()
>>> result.group_name is not None
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
Close
Hashes for sqlalchemy_bundle_model-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2402827638c3ef3edf2094efbaff1ada5dcd7ebba64dec8a8c65c877e407083 |
|
MD5 | 52ca198649cbf2936b772b530530bd51 |
|
BLAKE2b-256 | c92ca2ae1e171d212275d24e5595895186a4d25602ca694584cdb963020fb200 |
Close
Hashes for sqlalchemy_bundle_model-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f448b281685d0fe0cf04c86b06a4a4de7be497665c3fd8a9ff6dcb930e7264e2 |
|
MD5 | ce08789613eaf0ec78f487ad16e237e0 |
|
BLAKE2b-256 | 7a27cc2eb0670287903e393f116bb6768f4f296f573dffb95d56095a0d5ad143 |