本文整理汇总了Python中models.User.where方法的典型用法代码示例。如果您正苦于以下问题:Python User.where方法的具体用法?Python User.where怎么用?Python User.where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_count
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_count(self):
self.create_data(4, table=1)
query = User.where(User.id > 4).select()
result = query.execute()
assert result.count == 0
query = User.where(User.id > 3).select()
result = query.execute()
assert result.count == 1
示例2: test_reset_data
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_reset_data(self):
User.where(User.name == 'hello')
assert User.runtime.data['where']
User.where(User.name == 'x').select()
for runtime_key, runtime_data in User.runtime.data.items():
assert not runtime_data
User.at(7).select()
for runtime_key, runtime_data in User.runtime.data.items():
assert not runtime_data
示例3: test_where
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_where(self):
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
User.create(name='tom', email='[email protected]')
assert ['jack'] == [
user.name for user in User.where(name='jack').select()]
assert [1] == [
user.id for user in User.where(id=1).select()
]
assert ['tom'] == [
user.name for user in User.where(User.name.like('t%')).select()]
示例4: test_select
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_select(self):
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
User.create(name='tom', email='[email protected]')
### select all fields
query = User.select()
result = query.execute()
assert result.count == 3
for user in result.all():
assert '%[email protected]' % user.name == user.email
### select part fields
query = User.select(User.name)
result = query.execute()
assert result.count == 3
jack = result.one()
assert jack.name == 'jack'
amy = result.one()
assert amy.name == 'amy'
tom = result.one()
assert tom.name == 'tom'
assert result.one() is None
### select with where
query = User.where(name='jack').select()
result = query.execute()
assert result.count == 1
assert result.one().name == 'jack'
示例5: test_delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_delete(self):
self.create_data(4, table=1)
assert User.at(1).delete().execute() == 1
assert User.where(
(User.name == 'name1') | (User.name == 'name2')
).delete().execute() == 1
assert User.count() == 2
示例6: test_not_in_select
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_not_in_select(self):
self.create_data(4)
query = User.where(
User.id.not_in(Post.select(Post.user_id))
).select()
results = query.execute()
assert results.count == 0
示例7: test_subquery
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_subquery(self):
self.create_data(10)
query = User.where(User.id._in(Post.select(Post.user_id))).select()
result = query.execute()
assert result.count == 10
query = User.where(id=(Post.select(fn.max(Post.user_id)))).select()
result = query.execute()
assert result.count == 1
assert result.one().id == 10
query = User.where(
User.id < Post.select(fn.min(Post.user_id))).select()
result = query.execute()
assert result.count == 0
示例8: test_iter
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_iter(self):
self.create_data(4)
i = 0
for user in User.where(User.id < 3).select(User.id):
i = i + 1
assert user.id == i
assert i == 2
示例9: test_expr_priority
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_expr_priority(self):
assert User.create(name='jack', email='[email protected]')
query = User.where(
(User.id < 0) & (
(User.name == 'jack') | (User.email == '[email protected]'))
).select()
results = query.execute()
assert results.count == 0
示例10: test_expr_priority
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_expr_priority(self):
assert User.create(name='jack', email='[email protected]')
# query should be:
# "(id < 0) and (name='jack' or email='[email protected]')" => 0 rows
# but not be:
# "id < 0 and name = 'jack' or email='[email protected]'" => 1 rows
query = User.where(
(User.id < 0) & (
(User.name == 'jack') | (User.email == '[email protected]')
)
).select()
assert query.execute().count == 0 # not 1
query = User.where(
(User.id < 0) & (
User.name == 'jack') | (User.email == '[email protected]')
).select()
assert query.execute().count == 1
示例11: test_all
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_all(self):
self.create_data(3, table=1)
query = User.where(User.id > 1, User.id < 3).select()
results = query.execute()
assert results.count == 1
for user in results.all():
assert user.id == 2
idx = 0
for user in User.select():
idx = idx + 1
assert user.id == idx
示例12: test_select
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_select(self):
self.create_data(4, table=4)
query = User.at(1).select()
results = query.execute()
assert results.count == 1
user = results.one()
assert user.id == 1 and user._in_db is True
query = User.where(User.id < 3).select(User.name)
results = query.execute()
for user in results.all():
assert user.name
assert results.count == 2
示例13: test_where
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_where(self):
self.create_data(3, table=1)
assert User.where(User.id == 1) is User
assert User.where(id=1) is User
User.runtime.reset_data()
assert User.where(User.name == 'name1').select().execute().count == 1
assert User.where(User.name == 'name1',
User.email == 'email').select().execute().count == 0
assert User.where(
User.name.like('name%')).select().execute().count == 3
assert User.where(
User.id.between(0, 4)).select().execute().count == 3
示例14: test_subquery
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
def test_subquery(self):
self.create_data(10)
query = User.where(User.id._in(Post.select(Post.user_id))).select()
results = query.execute()
assert results.count == 10
示例15: where
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import where [as 别名]
from models import User
# select user.id from user where (user.id > '1' and (user.name = 'jack' or user.email = '[email protected]'))
User.where((User.id > 1) & ((User.name == "jack") | (User.email == "[email protected]"))).select(User.id)