From 298645ffdb05de2f85113c31cedf7654147fee66 Mon Sep 17 00:00:00 2001 From: Alex Groleau Date: Wed, 18 Mar 2026 02:42:20 -0400 Subject: [PATCH] queryer fixes --- reorder.py | 69 ---------------------- t10.json | 54 ------------------ t4.json | 164 ----------------------------------------------------- 3 files changed, 287 deletions(-) delete mode 100644 reorder.py delete mode 100644 t10.json delete mode 100644 t4.json diff --git a/reorder.py b/reorder.py deleted file mode 100644 index 47cb7bc..0000000 --- a/reorder.py +++ /dev/null @@ -1,69 +0,0 @@ -import sys - -with open("src/queryer/compiler.rs", "r") as f: - text = f.read() - -def find_function(text, name): - pos = text.find(f" fn {name}(") - if pos == -1: - pos = text.find(f" pub fn {name}(") - if pos == -1: - return None, None, None - - # Capture documentation comments immediately above the function - doc_pos = pos - while True: - prev_newline = text.rfind("\n", 0, doc_pos) - if prev_newline == -1: break - line = text[prev_newline+1:doc_pos].strip() - if line.startswith("///") or line == "": - doc_pos = prev_newline - else: - break - - start_brace = text.find("{", pos) - depth = 1 - i = start_brace + 1 - while depth > 0 and i < len(text): - if text[i] == '{': depth += 1 - elif text[i] == '}': depth -= 1 - i += 1 - - return doc_pos + 1, i, text[doc_pos+1:i] - -# Desired order -funcs = [ - "compile", - "compile_node", - "compile_entity", - "compile_object", - "compile_one_of", - "compile_from_clause", - "compile_select_clause", - "compile_where_clause", - "get_merged_properties" -] - -blocks = {} -for f in funcs: - s, e, block = find_function(text, f) - if block: - blocks[f] = block.strip() - else: - print(f"Failed to find {f}") - sys.exit(1) - -impl_start = text.find("impl<'a> Compiler<'a> {") -header = text[:impl_start] + "impl<'a> Compiler<'a> {\n" -footer = "}\n\n" - -new_text = header -for f in funcs: - new_text += " " + blocks[f].replace("\n", "\n ") + "\n\n" -new_text = new_text.rstrip() + "\n}\n" - -# Remove extra indents injected back to the root level -new_text = new_text.replace(" \n", "\n").replace("\n }\n", "\n}\n") - -with open("src/queryer/compiler.rs", "w") as f: - f.write(new_text) diff --git a/t10.json b/t10.json deleted file mode 100644 index d89bae3..0000000 --- a/t10.json +++ /dev/null @@ -1,54 +0,0 @@ -[ - [ - "(SELECT jsonb_build_object(", - " 'id', organization_1.id,", - " 'type', CASE", - " WHEN organization_1.type = 'person' THEN", - " ((SELECT jsonb_build_object(", - " 'age', person_3.age,", - " 'archived', entity_5.archived,", - " 'created_at', entity_5.created_at,", - " 'first_name', person_3.first_name,", - " 'id', entity_5.id,", - " 'last_name', person_3.last_name,", - " 'name', entity_5.name,", - " 'type', entity_5.type", - " )", - " FROM agreego.person person_3", - " JOIN agreego.organization organization_4 ON organization_4.id = person_3.id", - " JOIN agreego.entity entity_5 ON entity_5.id = organization_4.id", - " WHERE", - " NOT entity_5.archived))", - " WHEN organization_1.type = 'bot' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'created_at', entity_8.created_at,", - " 'id', entity_8.id,", - " 'name', entity_8.name,", - " 'token', bot_6.token,", - " 'type', entity_8.type", - " )", - " FROM agreego.bot bot_6", - " JOIN agreego.organization organization_7 ON organization_7.id = bot_6.id", - " JOIN agreego.entity entity_8 ON entity_8.id = organization_7.id", - " WHERE", - " NOT entity_8.archived))", - " WHEN organization_1.type = 'organization' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_10.archived,", - " 'created_at', entity_10.created_at,", - " 'id', entity_10.id,", - " 'name', entity_10.name,", - " 'type', entity_10.type", - " )", - " FROM agreego.organization organization_9", - " JOIN agreego.entity entity_10 ON entity_10.id = organization_9.id", - " WHERE", - " NOT entity_10.archived))", - " ELSE NULL END", - ")", - "FROM agreego.organization organization_1", - "JOIN agreego.entity entity_2 ON entity_2.id = organization_1.id", - "WHERE NOT entity_2.archived)" - ] -] diff --git a/t4.json b/t4.json deleted file mode 100644 index 37c4aff..0000000 --- a/t4.json +++ /dev/null @@ -1,164 +0,0 @@ -[ - [ - "(SELECT jsonb_build_object(", - " 'addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_6.archived,", - " 'created_at', entity_6.created_at,", - " 'id', entity_6.id,", - " 'is_primary', contact_4.is_primary,", - " 'name', entity_6.name,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_8.archived,", - " 'city', address_7.city,", - " 'created_at', entity_8.created_at,", - " 'id', entity_8.id,", - " 'name', entity_8.name,", - " 'type', entity_8.type", - " )", - " FROM agreego.address address_7", - " JOIN agreego.entity entity_8 ON entity_8.id = address_7.id", - " WHERE", - " NOT entity_8.archived", - " AND relationship_5.target_id = address_7.id),", - " 'type', entity_6.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_4", - " JOIN agreego.relationship relationship_5 ON relationship_5.id = contact_4.id", - " JOIN agreego.entity entity_6 ON entity_6.id = relationship_5.id", - " WHERE", - " NOT entity_6.archived", - " AND contact_4.parent_id = entity_3.id),", - " 'age', person_1.age,", - " 'archived', entity_3.archived,", - " 'contacts',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_11.archived,", - " 'created_at', entity_11.created_at,", - " 'id', entity_11.id,", - " 'is_primary', contact_9.is_primary,", - " 'name', entity_11.name,", - " 'target', CASE", - " WHEN entity_11.target_type = 'address' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_17.archived,", - " 'city', address_16.city,", - " 'created_at', entity_17.created_at,", - " 'id', entity_17.id,", - " 'name', entity_17.name,", - " 'type', entity_17.type", - " )", - " FROM agreego.address address_16", - " JOIN agreego.entity entity_17 ON entity_17.id = address_16.id", - " WHERE", - " NOT entity_17.archived", - " AND relationship_10.target_id = address_16.id))", - " WHEN entity_11.target_type = 'email_address' THEN", - " ((SELECT jsonb_build_object(", - " 'address', email_address_14.address,", - " 'archived', entity_15.archived,", - " 'created_at', entity_15.created_at,", - " 'id', entity_15.id,", - " 'name', entity_15.name,", - " 'type', entity_15.type", - " )", - " FROM agreego.email_address email_address_14", - " JOIN agreego.entity entity_15 ON entity_15.id = email_address_14.id", - " WHERE", - " NOT entity_15.archived", - " AND relationship_10.target_id = email_address_14.id))", - " WHEN entity_11.target_type = 'phone_number' THEN", - " ((SELECT jsonb_build_object(", - " 'archived', entity_13.archived,", - " 'created_at', entity_13.created_at,", - " 'id', entity_13.id,", - " 'name', entity_13.name,", - " 'number', phone_number_12.number,", - " 'type', entity_13.type", - " )", - " FROM agreego.phone_number phone_number_12", - " JOIN agreego.entity entity_13 ON entity_13.id = phone_number_12.id", - " WHERE", - " NOT entity_13.archived", - " AND relationship_10.target_id = phone_number_12.id))", - " ELSE NULL END,", - " 'type', entity_11.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_9", - " JOIN agreego.relationship relationship_10 ON relationship_10.id = contact_9.id", - " JOIN agreego.entity entity_11 ON entity_11.id = relationship_10.id", - " WHERE", - " NOT entity_11.archived", - " AND contact_9.parent_id = entity_3.id),", - " 'created_at', entity_3.created_at,", - " 'email_addresses',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_20.archived,", - " 'created_at', entity_20.created_at,", - " 'id', entity_20.id,", - " 'is_primary', contact_18.is_primary,", - " 'name', entity_20.name,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'address', email_address_21.address,", - " 'archived', entity_22.archived,", - " 'created_at', entity_22.created_at,", - " 'id', entity_22.id,", - " 'name', entity_22.name,", - " 'type', entity_22.type", - " )", - " FROM agreego.email_address email_address_21", - " JOIN agreego.entity entity_22 ON entity_22.id = email_address_21.id", - " WHERE", - " NOT entity_22.archived", - " AND relationship_19.target_id = email_address_21.id),", - " 'type', entity_20.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_18", - " JOIN agreego.relationship relationship_19 ON relationship_19.id = contact_18.id", - " JOIN agreego.entity entity_20 ON entity_20.id = relationship_19.id", - " WHERE", - " NOT entity_20.archived", - " AND contact_18.parent_id = entity_3.id),", - " 'first_name', person_1.first_name,", - " 'id', entity_3.id,", - " 'last_name', person_1.last_name,", - " 'name', entity_3.name,", - " 'phone_numbers',", - " (SELECT COALESCE(jsonb_agg(jsonb_build_object(", - " 'archived', entity_25.archived,", - " 'created_at', entity_25.created_at,", - " 'id', entity_25.id,", - " 'is_primary', contact_23.is_primary,", - " 'name', entity_25.name,", - " 'target',", - " (SELECT jsonb_build_object(", - " 'archived', entity_27.archived,", - " 'created_at', entity_27.created_at,", - " 'id', entity_27.id,", - " 'name', entity_27.name,", - " 'number', phone_number_26.number,", - " 'type', entity_27.type", - " )", - " FROM agreego.phone_number phone_number_26", - " JOIN agreego.entity entity_27 ON entity_27.id = phone_number_26.id", - " WHERE", - " NOT entity_27.archived", - " AND relationship_24.target_id = phone_number_26.id),", - " 'type', entity_25.type", - " )), '[]'::jsonb)", - " FROM agreego.contact contact_23", - " JOIN agreego.relationship relationship_24 ON relationship_24.id = contact_23.id", - " JOIN agreego.entity entity_25 ON entity_25.id = relationship_24.id", - " WHERE", - " NOT entity_25.archived", - " AND contact_23.parent_id = entity_3.id),", - " 'type', entity_3.type", - ")", - "FROM agreego.person person_1", - "JOIN agreego.organization organization_2 ON organization_2.id = person_1.id", - "JOIN agreego.entity entity_3 ON entity_3.id = organization_2.id", - "WHERE NOT entity_3.archived)" - ] -]