def serialize_project(node, context): return IR.select( node.kind_name, filters=IR.filter( IR.attribute(None, "name"), IR.literal(node.name), "=" ), limit=1, )
def compile_constant(node, state): expr = IR.literal(node.value) # Constants are represented as repr(obj) in the # serialization part, so we have to re-cast it. if state.match == "Constant": expr.value = repr(expr.value) return IR.filter(state.compute_path(), expr, "=")
def compile_query(self): query = compile_query(self.reiz_ql, limit=None, offset=0) query.filters = IR.combine_filters( query.filters, IR.filter( IR.attribute(IR.attribute(None, "_module"), "filename"), IR.literal(self.expected_filename), "=", ), ) return IR.construct(query)
def metadata_parent(parent_node, state): state.ensure(parent_node, len(parent_node.filters) == 1) parent_field, filter_value = parent_node.filters.popitem() state.ensure(parent_node, filter_value is grammar.Ignore) with state.temp_pointer("_parent_types"): return IR.filter( IR.tuple( [parent_node.bound_node.type_id, IR.literal(parent_field)]), state.compute_path(), "IN", )
def convert_length(node, state, arguments): state.ensure(node, any((arguments.min, arguments.max))) count = IR.call("count", [state.compute_path()]) filters = None for value, operator in [ (arguments.min, IR.as_operator(">=")), (arguments.max, IR.as_operator("<=")), ]: if value is None: continue state.ensure(value, isinstance(value, grammar.Constant)) state.ensure(value, isinstance(value.value, int)) filters = IR.combine_filters( filters, IR.filter(count, IR.literal(value.value), operator)) assert filters is not None return filters
def serialize_string(value, context): return IR.literal(value)
def compile_match_string(node, state): expr = IR.literal(node.value) return IR.filter(state.compute_path(), expr, "LIKE")
def convert_intensive(node, state, arguments): match_str = arguments.match_str state.ensure(node, isinstance(match_str, grammar.MatchString)) return IR.filter(state.compute_path(), IR.literal(match_str.value), "ILIKE")