本文整理汇总了Python中model.DBSession.configure方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.configure方法的具体用法?Python DBSession.configure怎么用?Python DBSession.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.DBSession
的用法示例。
在下文中一共展示了DBSession.configure方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_db
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import configure [as 别名]
def init_db(path='eta.db'):
"""Initialze database
"""
engine = create_engine("sqlite:///%s" % path)
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)
log.info("Initialized database %s", path)
示例2: main
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import configure [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('article_list', '/')
config.add_route('show_article', '/article/{article}')
config.add_route('add_article', '/add_article')
config.scan()
# SQL Alchemy stuff.
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
try:
Base.metadata.create_all(engine)
with transaction.manager:
article = Article(title='Test article', body="Test test test")
DBSession.add(article)
except IntegrityError:
print "Skipping creating, integrity error was thrown"
return config.make_wsgi_app()
示例3: init_db
# 需要导入模块: from model import DBSession [as 别名]
# 或者: from model.DBSession import configure [as 别名]
def init_db(config):
settings = config.get_settings()
path = settings.get('db.path', 'var/eta.db')
engine = create_engine("sqlite:///%s" % path)
Base.metadata.create_all(engine)
DBSession.configure(bind=engine)