当前位置: 首页>>代码示例>>Python>>正文


Python ModuleType.session方法代码示例

本文整理汇总了Python中types.ModuleType.session方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.session方法的具体用法?Python ModuleType.session怎么用?Python ModuleType.session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types.ModuleType的用法示例。


在下文中一共展示了ModuleType.session方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _make_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import session [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
开发者ID:EnTeQuAk,项目名称:inyoka-legacy,代码行数:33,代码来源:database.py

示例2: _make_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import session [as 别名]
def _make_module():
    db = ModuleType('db')
    for mod in sqlalchemy, orm:
        for key, value in mod.__dict__.iteritems():
            if key in mod.__all__:
                setattr(db, key, value)

    db.session = session
    db.metadata = metadata
    db.Model = Model
    db.NoResultFound = orm.exc.NoResultFound
    return db
开发者ID:7thStreet,项目名称:lodgeit,代码行数:14,代码来源:database.py

示例3: ModuleType

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import session [as 别名]
import os
from types import ModuleType
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

db = ModuleType('db')

db.engine = create_engine('sqlite:///{path}/pastes.db'.format(path=os.path.abspath(os.curdir)),
                          convert_unicode=True)
db.session = scoped_session(sessionmaker(autocommit=False, autoflush=False,
                                         bind=db.engine))

db.Base = declarative_base()
db.Base.query = db.session.query_property()

def init():
    import ControlPaste.models
    db.Base.metadata.create_all(bind=db.engine)
开发者ID:alterecco,项目名称:ControlPaste,代码行数:21,代码来源:database.py

示例4: ModuleType

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import session [as 别名]

#: create a fake module for easy access to database session methods
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__
for name in 'delete', 'save', 'flush', 'execute', 'begin', 'query', \
            'commit', 'rollback', 'clear', 'refresh', 'expire':
    setattr(db, name, getattr(session, name))
db.session = session


recipients_table = db.Table('recipients', metadata,
    db.Column('id', db.Integer, primary_key=True),
    db.Column('name', db.String(100), nullable=False),
    db.Column('mail', db.String(100), nullable=False),
    db.Column('active', db.Boolean, nullable=False),
    db.Column('comment', db.String(100), nullable=True),
)


class Recipient(object):
    def __init__(self, name=None, mail=None, active=False, comment=None):
        self.name = name or u'unknown'
        self.mail = mail or u'unknown'
开发者ID:EnTeQuAk,项目名称:nms,代码行数:32,代码来源:database.py


注:本文中的types.ModuleType.session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。