Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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()
Release History

Release History

This version
History Node

0.0.2

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
sqlalchemy-manager-0.0.2.tar.gz (2.9 kB) Copy SHA256 Checksum SHA256 Source Apr 4, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting