本文整理汇总了Python中sqlalchemy_wrapper.SQLAlchemy.flush方法的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemy.flush方法的具体用法?Python SQLAlchemy.flush怎么用?Python SQLAlchemy.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy_wrapper.SQLAlchemy
的用法示例。
在下文中一共展示了SQLAlchemy.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_models_mixins
# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import flush [as 别名]
def test_models_mixins():
db = SQLAlchemy('sqlite:///:memory:')
class UserMixin(object):
email = db.Column(db.Unicode(300))
def __repr__(self):
return 'overwrited'
class RoleMixin(object):
description = db.Column(db.UnicodeText)
auth = authcode.Auth(SECRET_KEY, db=db, UserMixin=UserMixin, RoleMixin=RoleMixin)
User = auth.User
Role = auth.Role
db.create_all()
user = User(login=u'meh', password='foobar', email=u'[email protected]')
db.session.add(user)
db.flush()
assert User.__tablename__ == 'users'
assert user.login == u'meh'
assert user.email == u'[email protected]'
assert hasattr(user, 'password')
assert hasattr(user, 'last_sign_in')
assert repr(user) == 'overwrited'
assert hasattr(Role, 'description')
示例2: test_query
# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import flush [as 别名]
def test_query():
db = SQLAlchemy(URI1)
ToDo = create_test_model(db)
db.create_all()
db.add(ToDo('First', 'The text'))
db.add(ToDo('Second', 'The text'))
db.flush()
titles = ' '.join(x.title for x in db.query(ToDo).all())
assert titles == 'First Second'
data = db.query(ToDo).filter(ToDo.title == 'First').all()
assert len(data) == 1
示例3: test_model_helpers
# 需要导入模块: from sqlalchemy_wrapper import SQLAlchemy [as 别名]
# 或者: from sqlalchemy_wrapper.SQLAlchemy import flush [as 别名]
def test_model_helpers():
db = SQLAlchemy()
class Row(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(60), nullable=False)
created_at = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)
db.create_all()
db.add(Row(name='a'))
db.flush()
row = db.query(Row).first()
assert str(row) == '<Row>'
assert dict(row)['name'] == 'a'