Skip to main content

Manager for SQLAlchemy

Project description

Manager for model, methods added in runtime to query.

Installation

$ [sudo] pip install sqlalchemy-manager

Documentation

alchmanager.ManagedQuery

Manager for Query.

Example

from sqlalchemy.orm import sessionmaker

from alchmanager import ManagedQuery, ManagedSession


engine = create_engine('sqlite:///:memory:')
session = sessionmaker(query_cls=ManagedQuery,
                       bind=engine)()
Base = declarative_base()

class MainManager:

    @staticmethod
    def is_index(query):
        return query.filter_by(is_index=True)

    @staticmethod
    def is_public(query):
        return query.filter_by(is_public=True)

class Test(Base):
    id = Column(Integer, primary_key=True)
    is_public = Column(Boolean, default=False)
    is_index = Column(Boolean)

    __manager__ = MainManager

session.query(Video).is_index().filter_by(id=1).is_public()

alchmanager.ManagedSession

Manager for Session. Decorator load_manager() for register methods into session.

Example

from sqlalchemy.orm import sessionmaker
from alchmanager import ManagedQuery, ManagedSession

engine = create_engine('sqlite:///:memory:')
session = sessionmaker(class_=ManagedSession,
                       bind=engine)()


@session.load_manager()
class MainSessionManager:

    @staticmethod
    def published(query):
        return query.filter_by(is_public=True)

    @staticmethod
    def has_index(query):
        return query.filter_by(is_index=True)

session.query(TestModel).has_index().published().count()

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-manager-0.0.2.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file sqlalchemy-manager-0.0.2.tar.gz.

File metadata

File hashes

Hashes for sqlalchemy-manager-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c241d8435eeaa14f9d4c320e7f551c4690017b68b2b148742ff32555c95b720f
MD5 fc1b3573866e38c814a67eb1d48d7c71
BLAKE2b-256 9134d06bbc1018d9f387e7fb69d1609b772d27e084f62496c582b767852d6cfd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page