def db_session(request, settings): """SQLAlchemy session.""" transaction.commit() db.Session.remove() engine = db.make_engine(settings) db.bind_engine(engine, should_create=True, should_drop=True) api_db.use_session(db.Session) return db.Session
def db_session(request, settings): """SQLAlchemy session.""" engine = db.make_engine(settings) db.bind_engine(engine, should_create=True, should_drop=True) api_db.use_session(db.Session) def destroy(): transaction.commit() db.Session.remove() request.addfinalizer(destroy) return db.Session
def includeme(config): settings = config.registry.settings should_create = asbool(settings.get('h.db.should_create_all', False)) should_drop = asbool(settings.get('h.db.should_drop_all', False)) engine = make_engine(settings) # Add a property to all requests for easy access to the session. This means # that view functions need only refer to `request.db` in order to retrieve # the current database session. config.add_request_method(lambda req: Session(), name='db', reify=True) # Register a deferred action to bind the engine when the configuration is # committed. Deferring the action means that this module can be included # before model modules without ill effect. config.action(None, bind_engine, (engine,), { 'should_create': should_create, 'should_drop': should_drop }) api_db.use_session(Session)
def setup_database(settings): """Set up the database connection and create tables.""" engine = db.make_engine(settings) db.bind_engine(engine, should_create=True, should_drop=True) api_db.use_session(db.Session)
def setup_database(request, settings): """Set up the database connection and create tables.""" engine = engine_from_config(settings, 'sqlalchemy.') db.bind_engine(engine, should_create=True, should_drop=True) db.use_session(Session) request.addfinalizer(Session.remove)