本文整理汇总了Python中peewee.SelectQuery方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.SelectQuery方法的具体用法?Python peewee.SelectQuery怎么用?Python peewee.SelectQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.SelectQuery方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def add(self, value, clear_existing=False):
if clear_existing:
self.clear()
fd = self._field_descriptor
if isinstance(value, SelectQuery):
query = value.select(
SQL(str(self._instance.get_id())),
fd.rel_model._meta.primary_key)
fd.through_model.insert_from(
fields=[fd.src_fk, fd.dest_fk],
query=query).execute()
else:
if not isinstance(value, (list, tuple)):
value = [value]
if not value:
return
inserts = [{
fd.src_fk.name: self._instance.get_id(),
fd.dest_fk.name: rel_id}
for rel_id in self._id_list(value)]
fd.through_model.insert_many(inserts).execute()
示例2: remove
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def remove(self, value):
fd = self._field_descriptor
if isinstance(value, SelectQuery):
subquery = value.select(value.model_class._meta.primary_key)
return (fd.through_model
.delete()
.where(
(fd.dest_fk << subquery) &
(fd.src_fk == self._instance.get_id()))
.execute())
else:
if not isinstance(value, (list, tuple)):
value = [value]
if not value:
return
return (fd.through_model
.delete()
.where(
(fd.dest_fk << self._id_list(value)) &
(fd.src_fk == self._instance.get_id()))
.execute())
示例3: __set__
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def __set__(self, instance, value):
mtv = instance._meta.db_table
miv = instance._get_pk_value()
if (isinstance(value, SelectQuery) and
value.model_class == self.model_class):
UpdateQuery(self.model_class, {
self.model_type_field: mtv,
self.model_id_field: miv,
}).where(value._where).execute()
elif all(map(lambda i: isinstance(i, self.model_class), value)):
for obj in value:
setattr(obj, self.model_type_field.name, mtv)
setattr(obj, self.model_id_field.name, miv)
obj.save()
else:
raise ValueError('ReverseGFK field unable to handle "%s"' % value)
示例4: query_execute
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def query_execute(self, database):
ret = original_query_execute(self, database)
if hasattr(self, '_context'):
# Query has been marked as lazy during backref lookup
signals.lazy_load.send(
signals.get_worker(),
args=self._context['args'],
kwargs=self._context['kwargs'],
parser=parse_reverse_get,
)
if not isinstance(self, SelectQuery):
return ret
signal = (
signals.ignore_load
if is_single(self._offset, self._limit)
else signals.load
)
signal.send(
signals.get_worker(),
args=(self, ),
ret=list(ret),
parser=parse_load,
)
return ret
示例5: select
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def select(query):
"""Perform SELECT query asynchronously.
"""
assert isinstance(query, peewee.SelectQuery),\
("Error, trying to run select coroutine"
"with wrong query class %s" % str(query))
cursor = await _execute_query_async(query)
result = AsyncQueryWrapper(cursor=cursor, query=query)
try:
while True:
await result.fetchone()
except GeneratorExit:
pass
finally:
await cursor.release()
return result
示例6: add
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def add(self, value, clear_existing=False):
if clear_existing:
await self.clear()
fd = self._field_descriptor
if isinstance(value, SelectQuery):
query = value.select(
SQL(str(self._instance.get_id())),
fd.rel_model._meta.primary_key)
await fd.through_model.insert_from(
fields=[fd.src_fk, fd.dest_fk],
query=query).execute()
else:
if not isinstance(value, (list, tuple)):
value = [value]
if not value:
return
inserts = [{
fd.src_fk.name: self._instance.get_id(),
fd.dest_fk.name: rel_id}
for rel_id in self._id_list(value)]
await fd.through_model.insert_many(inserts).execute()
示例7: remove
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def remove(self, value):
fd = self._field_descriptor
if isinstance(value, SelectQuery):
subquery = value.select(value.model_class._meta.primary_key)
return await (fd.through_model
.delete()
.where(
(fd.dest_fk << subquery) &
(fd.src_fk == self._instance.get_id()))
.execute())
else:
if not isinstance(value, (list, tuple)):
value = [value]
if not value:
return
return await (fd.through_model
.delete()
.where(
(fd.dest_fk << self._id_list(value)) &
(fd.src_fk == self._instance.get_id()))
.execute())
示例8: __init__
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def __init__(self, query_or_model, paginate_by, page_var='page',
check_bounds=False):
self.paginate_by = paginate_by
self.page_var = page_var
self.check_bounds = check_bounds
if isinstance(query_or_model, SelectQuery):
self.query = query_or_model
self.model = self.query.model_class
else:
self.model = query_or_model
self.query = self.model.select()
示例9: get_object_or_404
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def get_object_or_404(query_or_model, *query):
if not isinstance(query_or_model, SelectQuery):
query_or_model = query_or_model.select()
try:
return query_or_model.where(*query).get()
except DoesNotExist:
abort(404)
示例10: default
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SelectQuery [as 别名]
def default(self, obj):
if isinstance(obj, peewee.SelectQuery):
return list(obj)
if isinstance(obj, db.BaseModel):
return obj.serialize()
elif isinstance(obj, datetime.datetime):
# dt_local = util.utc2local(obj)
return obj.isoformat() if obj else None
return JSONEncoder.default(self, obj)