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


Python peewee.SelectQuery方法代码示例

本文整理汇总了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() 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:24,代码来源:fields.py

示例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()) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:23,代码来源:fields.py

示例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) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:18,代码来源:gfk.py

示例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 
开发者ID:jmcarp,项目名称:nplusone,代码行数:26,代码来源:peewee.py

示例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 
开发者ID:05bit,项目名称:peewee-async,代码行数:22,代码来源:peewee_async.py

示例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() 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:24,代码来源:fields.py

示例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()) 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:23,代码来源:fields.py

示例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() 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:14,代码来源:flask_utils.py

示例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) 
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:9,代码来源:flask_utils.py

示例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) 
开发者ID:tomimick,项目名称:restpie3,代码行数:11,代码来源:webutil.py


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