queryer fixes

This commit is contained in:
2026-03-18 02:41:56 -04:00
parent 02e661d219
commit 330280ba48
5 changed files with 562 additions and 638 deletions

View File

@ -1024,7 +1024,7 @@
" 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),",
" AND contact_4.source_id = entity_3.id),",
" 'age', person_1.age,",
" 'archived', entity_3.archived,",
" 'contacts',",
@ -1085,7 +1085,7 @@
" 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),",
" AND contact_9.source_id = entity_3.id),",
" 'created_at', entity_3.created_at,",
" 'email_addresses',",
" (SELECT COALESCE(jsonb_agg(jsonb_build_object(",
@ -1115,7 +1115,7 @@
" 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),",
" AND contact_18.source_id = entity_3.id),",
" 'first_name', person_1.first_name,",
" 'id', entity_3.id,",
" 'last_name', person_1.last_name,",
@ -1148,7 +1148,7 @@
" 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),",
" AND contact_23.source_id = entity_3.id),",
" 'type', entity_3.type",
")",
"FROM agreego.person person_1",
@ -1261,7 +1261,7 @@
" 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),",
" AND contact_4.source_id = entity_3.id),",
" 'age', person_1.age,",
" 'archived', entity_3.archived,",
" 'contacts',",
@ -1323,7 +1323,7 @@
" WHERE",
" NOT entity_11.archived",
" AND contact_9.is_primary = ($11#>>'{}')::boolean",
" AND contact_9.parent_id = entity_3.id),",
" AND contact_9.source_id = entity_3.id),",
" 'created_at', entity_3.created_at,",
" 'email_addresses',",
" (SELECT COALESCE(jsonb_agg(jsonb_build_object(",
@ -1353,7 +1353,7 @@
" 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),",
" AND contact_18.source_id = entity_3.id),",
" 'first_name', person_1.first_name,",
" 'id', entity_3.id,",
" 'last_name', person_1.last_name,",
@ -1387,7 +1387,7 @@
" 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),",
" AND contact_23.source_id = entity_3.id),",
" 'type', entity_3.type",
")",
"FROM agreego.person person_1",

69
reorder.py Normal file
View File

@ -0,0 +1,69 @@
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)

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,13 @@ impl Queryer {
return Ok(cached_sql.value().clone());
}
let compiler = compiler::SqlCompiler::new(self.db.clone());
let compiler = compiler::Compiler {
db: &self.db,
filter_keys: filter_keys,
is_stem_query: stem_opt.is_some(),
alias_counter: 0,
};
match compiler.compile(schema_id, stem_opt, filter_keys) {
Ok(compiled_sql) => {
self

View File

@ -191,9 +191,9 @@ impl Expect {
}
Expr::Function(func) => {
if let sqlparser::ast::FunctionArguments::List(args) = &func.args {
if let Some(sqlparser::ast::FunctionArg::Unnamed(sqlparser::ast::FunctionArgExpr::Expr(
e,
))) = args.args.get(0)
if let Some(sqlparser::ast::FunctionArg::Unnamed(
sqlparser::ast::FunctionArgExpr::Expr(e),
)) = args.args.get(0)
{
Self::validate_expr(e, available_aliases, sql)?;
}