def contains(self, value): if isinstance(value, dict): rhs = Value(value, unpack=False) return Expression(self, HCONTAINS_DICT, rhs) elif isinstance(value, (list, tuple)): rhs = Value(value, unpack=False) return Expression(self, HCONTAINS_KEYS, rhs) return Expression(self, HCONTAINS_KEY, value)
def apply_default(self, table, column_name, field): default = field.default if callable_(default): default = default() return (self.make_context().literal('UPDATE ').sql( Entity(table)).literal(' SET ').sql( Expression(Entity(column_name), OP.EQ, field.db_value(default), flat=True)))
def concat(self, rhs): return Expression(self.as_json(True), OP.CONCAT, Json(rhs))
def Match(field, query, language=None): params = (language, query) if language is not None else (query, ) field_params = (language, field) if language is not None else (field, ) return Expression(fn.to_tsvector(*field_params), TS_MATCH, fn.to_tsquery(*params))
def match(self, query, language=None, plain=False): params = (language, query) if language is not None else (query, ) func = fn.plainto_tsquery if plain else fn.to_tsquery return Expression(self, TS_MATCH, func(*params))
def remove(self, *items): return Expression(cast_jsonb(self), JSONB_REMOVE, Value(list(items), unpack=False))
def contains(self, *items): return Expression(self, ACONTAINS, ArrayValue(self, items))
def match(lhs, rhs): return Expression(lhs, OP.MATCH, rhs)
def has_key(self, key): return Expression(self.as_json(True), JSONB_CONTAINS_KEY, key)
def contains(self, other): if isinstance(other, (list, dict)): return Expression(self, JSONB_CONTAINS, Json(other)) return Expression(cast_jsonb(self), JSONB_EXISTS, other)
def contains_any(self, *keys): return Expression(self, HCONTAINS_ANY_KEY, Value(list(keys), unpack=False))
def update(self, **data): return Expression(self, HUPDATE, data)
def __getitem__(self, key): return Expression(self, HKEY, Value(key))
def contains_any(self, *items): return Expression(self, ACONTAINS_ANY, ArrayValue(self, items))
def contains(self, other): clone = self.as_json(True) if isinstance(other, (list, dict)): return Expression(clone, JSONB_CONTAINS, Json(other)) return Expression(clone, JSONB_EXISTS, other)
def contains_all(self, *keys): return Expression(self.as_json(True), JSONB_CONTAINS_ALL_KEYS, Value(list(keys), unpack=False))
def contained_by(self, other): return Expression(cast_jsonb(self), JSONB_CONTAINED_BY, Json(other))
def contains_all(self, *items): return Expression(cast_jsonb(self), JSONB_CONTAINS_ALL_KEYS, Value(list(items), unpack=False))
def has_key(self, key): return Expression(cast_jsonb(self), JSONB_CONTAINS_KEY, key)
def inner(self, rhs): if isinstance(rhs, (list, dict)): rhs = Value(rhs, converter=self.db_value, unpack=False) return Expression(self, op, rhs)
def inner(self, rhs): return Expression(self, op, ArrayValue(self, rhs))