當前位置: 首頁>>代碼示例>>Python>>正文


Python peewee.Expression方法代碼示例

本文整理匯總了Python中peewee.Expression方法的典型用法代碼示例。如果您正苦於以下問題:Python peewee.Expression方法的具體用法?Python peewee.Expression怎麽用?Python peewee.Expression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在peewee的用法示例。


在下文中一共展示了peewee.Expression方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: match

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def match(lhs, rhs):
    return Expression(lhs, OP.MATCH, rhs) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:sqlite_ext.py

示例2: cast

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def cast(self, as_type):
    return Expression(self, OP.CAST, SQL(as_type)) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:postgres_ext.py

示例3: contains

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def contains(self, other):
        clone = self.as_json(True)
        if isinstance(other, (list, dict)):
            return Expression(clone, OP.JSONB_CONTAINS, Json(other))
        return Expression(clone, OP.JSONB_EXISTS, other) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:7,代碼來源:postgres_ext.py

示例4: contains_any

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def contains_any(self, *keys):
        return Expression(
            self.as_json(True),
            OP.JSONB_CONTAINS_ANY_KEY,
            Passthrough(list(keys))) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:7,代碼來源:postgres_ext.py

示例5: __getitem__

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def __getitem__(self, key):
        return Expression(self, OP.HKEY, Param(key)) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:postgres_ext.py

示例6: update

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def update(self, **data):
        return Expression(self, OP.HUPDATE, data) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:postgres_ext.py

示例7: contained_by

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def contained_by(self, other):
        return Expression(self, OP.JSONB_CONTAINED_BY, Json(other)) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:postgres_ext.py

示例8: contains_all

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def contains_all(self, *items):
        return Expression(
            self,
            OP.JSONB_CONTAINS_ALL_KEYS,
            Passthrough(list(items))) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:7,代碼來源:postgres_ext.py

示例9: match

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def match(self, query):
        return Expression(self, OP.TS_MATCH, fn.to_tsquery(query)) 
開發者ID:danielecook,項目名稱:Quiver-alfred,代碼行數:4,代碼來源:postgres_ext.py

示例10: title

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def title(self):
        return Expression(
            fn.UPPER(fn.SUBSTR(self.username, 1, 1)),
            OP_CONCAT,
            fn.SUBSTR(self.username, 2)) 
開發者ID:kszucs,項目名稱:aiopeewee,代碼行數:7,代碼來源:test_shortcuts.py

示例11: pg_regex_i

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def pg_regex_i(lhs, rhs):
    return Expression(lhs, OP.IRGX, rhs) 
開發者ID:b1naryth1ef,項目名稱:rowboat,代碼行數:4,代碼來源:sql.py

示例12: set_default

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def set_default(db, migrator, table_name, column_name, field):
    default = field.default
    if callable(default): default = default()
    migration = ( migrator.make_context()
      .literal('UPDATE ').sql(pw.Entity(table_name))
      .literal(' SET ').sql(pw.Expression(pw.Entity(column_name), pw.OP.EQ, field.db_value(default), flat=True))
      .literal(' WHERE ').sql(pw.Expression(pw.Entity(column_name), pw.OP.IS, pw.SQL('NULL'), flat=True))
    )
    return extract_query_from_migration(migration) 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:11,代碼來源:peeweedbevolve.py

示例13: update

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import Expression [as 別名]
def update(self, records: Iterable[DataRecord], values: SQLValuesToWrite, returning=False) -> Union[int, Iterable[DataRecord]]:
        new_vals = {}
        model = self.vcls.model
        db = self.vcls.model._meta.database
        fields = self.vcls._peewee_fields
        cond = self._build_write_condition(records)

        for k, v in values.items():
            if k in fields:
                field = fields[k]
                is_array_field = isinstance(field, ArrayField)

                if is_array_field:
                    if k in values.set_add_fields:
                        # 這裏需要加 [v] 的原因是,params需要數組,舉例來說為,[v1,v2,v3]
                        # v = SQL('%s || %%s' % field.column_name, [v])
                        v = SQL('(select ARRAY((select unnest(%s)) union (select unnest(%%s))))' % field.column_name, [v])

                    if k in values.set_remove_fields:
                        v = SQL('(select ARRAY((select unnest(%s)) except (select unnest(%%s))))' % field.column_name, [v])

                    # 尚未啟用
                    # if k in values.array_append:
                    #     v = SQL('array_append(%s, %%s)' % field.column_name, [v])

                    # if k in values.array_remove:
                    #     v = SQL('array_remove(%s, %%s)' % field.column_name, [v])

                else:
                    if k in values.incr_fields:
                        v = field + v
                    if k in values.decr_fields:
                        v = field - v

                new_vals[k] = v

        with db.atomic(), PeeweeContext(db):
            if isinstance(db, peewee.PostgresqlDatabase):
                q = model.update(**new_vals).where(cond)
                if returning:
                    # cond: peewee.Expression
                    ret = q.returning(*model._meta.fields.values()).execute()
                    to_record = lambda x: PeeweeDataRecord(None, x, view=self.vcls)
                    items = map(to_record, ret)
                    return list(items)
                else:
                    count = q.execute()
                    return count
            else:
                count = model.update(**new_vals).where(cond).execute()
                if not returning: return count

                to_record = lambda x: PeeweeDataRecord(None, x, view=self.vcls)
                return list(map(to_record, model.select().where(cond).execute())) 
開發者ID:fy0,項目名稱:slim,代碼行數:56,代碼來源:sqlfuncs.py


注:本文中的peewee.Expression方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。