本文整理汇总了Python中types.ModuleType.get_engine方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.get_engine方法的具体用法?Python ModuleType.get_engine怎么用?Python ModuleType.get_engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.get_engine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_module
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import get_engine [as 别名]
def _make_module():
db = ModuleType('db')
_get_items = lambda mod: ((key, getattr(mod, key)) for key in mod.__all__)
modules = (_get_items(sqlalchemy), _get_items(orm))
for module in modules:
for key, value in module:
setattr(db, key, value)
# support for postgresql array type
from sqlalchemy.dialects.postgresql.base import PGArray
db.PGArray = PGArray
db.get_engine = get_engine
db.session = session
db.metadata = metadata
db.mapper = mapper
db.atomic_add = atomic_add
db.no_autoflush = no_autoflush
db.find_next_increment = find_next_increment
db.select_blocks = select_blocks
db.driver = driver
db.Model = Model
db.Query = Query
db.File = File
db.SlugGenerator = SlugGenerator
db.GuidGenerator = GuidGenerator
db.AttributeExtension = AttributeExtension
db.ColumnProperty = orm.ColumnProperty
db.NoResultFound = orm.exc.NoResultFound
db.SQLAlchemyError = exc.SQLAlchemyError
return db
示例2: ModuleType
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import get_engine [as 别名]
local.application.sqla_db_engine,
autoflush=True, transactional=True),
local_manager.get_ident)
#: create a new module for all the database related functions and objects
db = ModuleType('db')
key = value = mod = None
for mod in sqlalchemy, orm:
for key, value in mod.__dict__.iteritems():
if key in mod.__all__:
setattr(db, key, value)
del key, mod, value
db.__doc__ = __doc__
db.mapper = mapper
db.get_engine = lambda: local.application.database_engine
for name in 'delete', 'save', 'flush', 'execute', 'begin', \
'commit', 'rollback', 'clear', 'refresh', 'expire':
setattr(db, name, getattr(session, name))
db.session = session
db.DatabaseManager = DatabaseManager
#: support for SQLAlchemy's 0.4.2 Text type, in older versions it's
#: just Text. This patch will go away once SQLAlchemy 0.5 is out
#: or something like that.
if not hasattr(db, 'Text'):
db.Text = db.String
#: called at the end of a request
cleanup_session = session.remove