Skip to content

Instantly share code, notes, and snippets.

@amitm
Last active December 31, 2015 01:49
Show Gist options
  • Save amitm/7916920 to your computer and use it in GitHub Desktop.
Save amitm/7916920 to your computer and use it in GitHub Desktop.
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