def includeme(config): # Add a directive to get an alembic configuration. config.add_directive("alembic_config", _configure_alembic) # Create our SQLAlchemy Engine. config.registry["sqlalchemy.engine"] = sqlalchemy.create_engine( config.registry.settings["database.url"], isolation_level="SERIALIZABLE", ) # Register our request.db property config.add_request_method(_create_session, name="db", reify=True)
def includeme(config): LOGGER.info("Adding DB session...") # use pyramid_tm to hook the transaction lifecycle to the request config.include("pyramid_tm") session_factory = get_session_factory(get_engine(config)) config.registry["db_session_factory"] = session_factory # make `request.db` available for use in Pyramid config.add_request_method( # r.tm is the transaction manager used by pyramid_tm lambda r: get_tm_session(session_factory, r.tm), "db", reify=True)
def includeme(config): # Add a directive to get an alembic configuration. config.add_directive("alembic_config", _configure_alembic) # Create our SQLAlchemy Engine. config.registry["sqlalchemy.engine"] = _create_engine( config.registry.settings["database.url"]) # Register our request.db property config.add_request_method(_create_session, name="db", reify=True) # Add a route predicate to mark a route as read only. config.add_route_predicate("read_only", ReadOnlyPredicate) # Add a request.read_only property which can be used to determine if a # request is being acted upon as a read-only request or not. config.add_request_method(_readonly, name="read_only", reify=True)
def includeme(config): # Add a directive to get an alembic configuration. config.add_directive("alembic_config", _configure_alembic) # Create our SQLAlchemy Engine. config.registry["sqlalchemy.engine"] = _create_engine( config.registry.settings["database.url"], ) # Register our request.db property config.add_request_method(_create_session, name="db", reify=True) # Add a route predicate to mark a route as read only. config.add_route_predicate("read_only", ReadOnlyPredicate) # Add a request.read_only property which can be used to determine if a # request is being acted upon as a read-only request or not. config.add_request_method(_readonly, name="read_only", reify=True)
def includeme(config): # Hook request lifecycle to a transaction and retry transient failures config.include('pyramid_tm') config.include('pyramid_retry') # Add a directive to get an alembic configuration. config.add_directive("alembic_config", _configure_alembic) # Create our SQLAlchemy Engine. config.add_directive("sqlalchemy_engine", _create_engine) config.add_directive("add_model", attach_model_to_base) # Register our request.db property config.add_request_method(_create_session, name="db", reify=True) # Add a route predicate to mark a route as read only. config.add_view_deriver(readonly_view_deriver, under=INGRESS) config.scan('.')