當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。