def cand(*conditions): def build(attrs): return ' AND '.join( [f'({cond.expression(attrs)})' for cond in conditions]) attributes = merge([cond.attributes for cond in conditions]) references = flatten([cond.references for cond in conditions]) return Condition(build, attributes, references=references)
def between(value_a, value_b): value_a_key = f'{name}_a' value_b_key = f'{name}_b' def build(attrs): alias = get_safe_alias(name) value_a_attr = find_attr(attrs, original_name=value_a_key) value_b_attr = find_attr(attrs, original_name=value_b_key) return f'{alias} BETWEEN {value_a_attr.key} AND {value_b_attr.key}' return Condition(build, { value_a_key: value_a, value_b_key: value_b }, references=[name])
def begins_with(value): def build(attrs): a = find_attr(attrs) return f'begins_with({a.alias}, {a.key})' return Condition(build, {name: value})
def greater_than_or_equal(value): def build(attrs): a = find_attr(attrs) return f'{a.alias} >= {a.key}' return Condition(build, {name: value})
def less_than(value): def build(attrs): a = find_attr(attrs) return f'{a.alias} < {a.key}' return Condition(build, {name: value})
def equals(value): def build(attrs): a = find_attr(attrs) return f'{a.alias} = {a.key}' return Condition(build, {name: value})