本文整理汇总了Python中models.User.count方法的典型用法代码示例。如果您正苦于以下问题:Python User.count方法的具体用法?Python User.count怎么用?Python User.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.count方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [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
示例2: test_delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_delete(self):
if db_type != 'sqlite': # sqlite dosen't support 'delete xx from xxx'
assert self.models.where(
User.id == Post.user_id).delete().execute() == 8
assert self.models.where(
User.id == Post.user_id).select().execute().count == 0
assert Post.count() == 0
assert User.count() == 0
示例3: test_count
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_count(self):
self.create_data(4)
assert User.count() == 4
assert Post.count() == 4
query = User.select(fn.count(User.id))
result = query.execute()
assert result.count == 1
assert result.tuples()[0][0] == 4
示例4: test_count
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_count(self):
self.create_data(4)
assert User.count() == 4
query = (Post & User).select(
fn.count(User.id).alias('count_user_id'),
fn.count(Post.post_id).alias('count_post_id'))
results = query.execute()
assert results.count == 1
func = results.one()
assert func.count_user_id == 4
assert func.count_post_id == 4
示例5: test_transaction
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_transaction(self):
database.set_autocommit(False)
with database.transaction() as t:
User.create(name='jack', email='[email protected]')
with database.transaction() as t:
try:
User.create(name='amy', id=1)
except:
t.rollback()
database.set_autocommit(True)
assert User.count() == 1
示例6: test_create
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_create(self):
user = User.create(name='jack', email='[email protected]')
assert user.data == {
'name': 'jack', 'email': '[email protected]', 'id': 1
}
assert user in User
assert user._in_db
assert User.count() == 1
_user = User.getone()
assert _user.data == user.data
assert _user._in_db
示例7: test_update
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_update(self):
user = User.create(name='jack', email='[email protected]')
assert user.id == 1
assert user.name == 'jack'
assert user.email == '[email protected]'
assert User.count() == 1
query = User.at(1).update(email='[email protected]')
rows_affected = query.execute()
assert rows_affected == 1
user = User.getone()
assert user.id == 1 and user.email == '[email protected]'
示例8: delete
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def delete(self,id):
if not current_user.is_admin() and current_user.id != id:
abort(401)
if User.count() <= 1:
abort(403)
user = User.get_by_id(id)
try:
if user is None:
raise Exception(gettext('User not found'))
name = user.name
User.delete(user.id)
flash(gettext('The user "%(name)s" was removed', name=name))
except:
flash(gettext('Error while removing the user'), 'error')
if request.method == 'POST':
return redirect(url_for('UsersView:index'))
return jsonify(redirect_to=url_for('UsersView:index'))
示例9: test_inst_save
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_inst_save(self):
user = User(name='jack', email='[email protected]')
assert user.save() == 1 # insert
assert user._in_db and user in User
assert User.count() == 1
assert User.getone().name == 'jack'
user.email = '[email protected]'
assert user.save() == 1 # update
assert User.getone().email == '[email protected]'
# test inst._cache
assert user.save() == 0 # nothing change
user = User(name='jack', email='[email protected]')
user.set_in_db(True)
try:
user.save()
except PrimaryKeyValueNotFound:
pass
else:
raise Exception
示例10: test_model_inst_save
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_model_inst_save(self):
user = User(name='jack', email='[email protected]')
assert user.save() == 1
assert User.count() == 1
assert User.getone().name == 'jack'
user.name = 'amy'
assert user.save() == 1
assert User.findone(id=1).name == 'amy'
user = User(name='test!', email='[email protected]')
id = user.save()
assert id == 2
assert User.at(2).getone().name == 'test!'
user.name = 'run a test!'
rows_affected = user.save()
assert rows_affected == 1
query = User.at(2).select(User.name)
results = query.execute()
user = results.one()
try:
user.name = 'hello'
user.save()
except PrimaryKeyValueNotFound:
pass
示例11:
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
from models import User
count = User.count()
max_id = User.max(User.id)
min_id = User.min(User.id)
sum_of_ids = User.sum(User.id)
avg_of_ids = User.avg(User.id)
示例12: test_insert
# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
def test_insert(self):
query = User.insert(name='jack', email='[email protected]')
assert query.execute() == 1
assert User.count() == 1
user = User.getone()
assert user.name == 'jack' and user.email == '[email protected]'