Last active
December 31, 2015 01:49
-
-
Save amitm/7916920 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.orm import scoped_session, sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
class Scope(object): | |
def __init__(self): | |
self._current_scope = None | |
def set(self, scope): | |
self._current_scope = scope | |
def get(self): | |
return self._current_scope | |
scope = Scope() | |
db = scoped_session(sessionmaker(autocommit=False, | |
autoflush=True, | |
expire_on_commit=False, | |
bind=engine | |
scopefunc=scope.get)) | |
Base = declarative_base() | |
Base.query = db.query_property() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment