本文整理汇总了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)
示例2: cast
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Expression [as 别名]
def cast(self, as_type):
return Expression(self, OP.CAST, SQL(as_type))
示例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)
示例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)))
示例5: __getitem__
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Expression [as 别名]
def __getitem__(self, key):
return Expression(self, OP.HKEY, Param(key))
示例6: update
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Expression [as 别名]
def update(self, **data):
return Expression(self, OP.HUPDATE, data)
示例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))
示例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)))
示例9: match
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Expression [as 别名]
def match(self, query):
return Expression(self, OP.TS_MATCH, fn.to_tsquery(query))
示例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))
示例11: pg_regex_i
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import Expression [as 别名]
def pg_regex_i(lhs, rhs):
return Expression(lhs, OP.IRGX, rhs)
示例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)
示例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()))