How to use the peewee.Expression function in peewee

To help you get started, we’ve selected a few peewee examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github insolite / graphene-peewee-async / graphene_peewee_async / queries.py View on Github external
op = DJANGO_MAP[op]
        elif value is None:
            op = OP.IS
        else:
            op = OP.EQ
        for piece in key.split('__'):
            model_attr = getattr(curr, piece)
            if isinstance(model_attr, FieldAlias):
                actual_model_attr = model_attr.field
            else:
                actual_model_attr = model_attr
            if value is not None and isinstance(actual_model_attr, relationship):
                curr = model_attr.rel_model
                curr = alias_map.get(curr, curr)
                joins.append(model_attr)
        accum.append(Expression(model_attr, op, value))
    return accum, joins
github coleifer / peewee / peewee.py View on Github external
def __init__(self, lhs, op, rhs, flat=False):
        super(Expression, self).__init__()
        self.lhs = lhs
        self.op = op
        self.rhs = rhs
        self.flat = flat
github coleifer / peewee / playhouse / postgres_ext.py View on Github external
def inner(self, rhs):
            return Expression(self, op, ArrayValue(self, rhs))
        return inner
github trakt / Plex-Trakt-Scrobbler / Trakttv.bundle / Contents / Libraries / Shared / playhouse / postgres_ext.py View on Github external
def match(self, query):
        return Expression(self, OP.TS_MATCH, fn.to_tsquery(query))
github coleifer / peewee / playhouse / sqlite_ext.py View on Github external
def match(lhs, rhs):
    return Expression(lhs, OP.MATCH, rhs)
github coleifer / peewee / playhouse / postgres_ext.py View on Github external
def contains_any(self, *items):
        return Expression(self, ACONTAINS_ANY, ArrayValue(self, items))
github theotherp / nzbhydra / libs / playhouse / postgres_ext.py View on Github external
def contains(self, value):
        if isinstance(value, dict):
            return Expression(self, OP.HCONTAINS_DICT, Param(value))
        elif isinstance(value, (list, tuple)):
            return Expression(self, OP.HCONTAINS_KEYS, Param(value))
        return Expression(self, OP.HCONTAINS_KEY, value)
github coleifer / peewee / playhouse / postgres_ext.py View on Github external
def has_key(self, key):
        return Expression(cast_jsonb(self), JSONB_CONTAINS_KEY, key)
github insolite / graphene-peewee-async / graphene_peewee_async / queries.py View on Github external
# normalize args and kwargs into a new expression
    # Note: This is a modified peewee's Query.filter method.
    # Inner methods convert_dict_to_node and ensure_join also changed.
    # That is done to support FieldProxy generated from aliases to prevent unnecessary joins (see issue link below).
    # https://github.com/coleifer/peewee/issues/1338
    if filters:
        dq_node = Node() & DQ(**filters)
    else:
        return query

    # dq_node should now be an Expression, lhs = Node(), rhs = ...
    q = deque([dq_node])
    dq_joins = set()
    while q:
        curr = q.popleft()
        if not isinstance(curr, Expression):
            continue
        for side, piece in (('lhs', curr.lhs), ('rhs', curr.rhs)):
            if isinstance(piece, DQ):
                new_query, joins = convert_dict_to_node(query, piece.query, alias_map)
                dq_joins.update(joins)
                expression = reduce(operator.and_, new_query)
                # Apply values from the DQ object.
                expression._negated = piece._negated
                expression._alias = piece.alias
                setattr(curr, side, expression)
            else:
                q.append(piece)

    dq_node = dq_node.rhs

    new_query = query.clone()
github coleifer / peewee / playhouse / postgres_ext.py View on Github external
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)