本文整理汇总了Python中zope.sqlalchemy.ZopeTransactionExtension方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.ZopeTransactionExtension方法的具体用法?Python sqlalchemy.ZopeTransactionExtension怎么用?Python sqlalchemy.ZopeTransactionExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zope.sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.ZopeTransactionExtension方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_session
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def make_session(transaction=True, autoflush=False, autocommit=False):
# Yeah the arguments and their naming is so terrible. sorry
config = ConfigParser.ConfigParser()
config.read('production.ini')
db_url = os.environ.get("FANTASYDOTA_DB")
engine = create_engine(db_url, echo=False)
if transaction:
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
else:
DBSession = sessionmaker(autoflush=autoflush, autocommit=autocommit)
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
session = DBSession()
return session
示例2: main
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def main(global_config, **main_settings):
app_config = Config(global_config["__file__"])
app_config.read()
mm_settings = app_config["mishmash"]
engine_args = dict(database.DEFAULT_ENGINE_ARGS)
pfix, plen = "sqlalchemy.", len("sqlalchemy.")
# Strip prefix and remove url value
sql_ini_args = {
name[plen:]: mm_settings[name]
for name in mm_settings
if name.startswith(pfix) and not name.endswith(".url")
}
engine_args.update(sql_ini_args)
(engine,
SessionMaker,
connection) = database.init(app_config.db_url,
engine_args=engine_args, scoped=True,
trans_mgr=ZopeTransactionExtension())
pyra_config = _configure(main_settings, SessionMaker)
return pyra_config.make_wsgi_app()
示例3: initialize_sql
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def initialize_sql(settings):
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
# Here, we configure our transaction manager to keep the session open
# after a commit.
# - This of course means that we need to manually close the session when
# we are done.
DBSession.configure(extension=ZopeTransactionExtension())
Base.metadata.create_all(engine)
示例4: __init__
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def __init__(self, db_path):
self.base = declarative_base()
self.engine = create_engine(db_path, convert_unicode=True, pool_size=100)
#self.base.prepare(self.engine, reflect=True)
self.session = scoped_session(sessionmaker(bind=self.engine, twophase=True, extension=ZopeTransactionExtension()))
#self.session = scoped_session(sessionmaker(bind=self.engine))
register(self.session, keep_session=True)
示例5: make_session_maker
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def make_session_maker(zope_tr=True, autoflush=True):
return scoped_session(sessionmaker(
autoflush=autoflush,
extension=ZopeTransactionExtension() if zope_tr else None))
示例6: is_zopish
# 需要导入模块: from zope import sqlalchemy [as 别名]
# 或者: from zope.sqlalchemy import ZopeTransactionExtension [as 别名]
def is_zopish():
return isinstance(
_session_maker.session_factory.kw.get('extension'),
ZopeTransactionExtension)