stems removed from queryer
This commit is contained in:
@ -3,7 +3,6 @@ use std::sync::Arc;
|
||||
pub struct Compiler<'a> {
|
||||
pub db: &'a Database,
|
||||
pub filter_keys: &'a [String],
|
||||
pub is_stem_query: bool,
|
||||
pub alias_counter: usize,
|
||||
}
|
||||
|
||||
@ -15,7 +14,7 @@ pub struct Node<'a> {
|
||||
pub parent_type: Option<&'a crate::database::r#type::Type>,
|
||||
pub property_name: Option<String>,
|
||||
pub depth: usize,
|
||||
pub stem_path: String,
|
||||
pub ast_path: String,
|
||||
}
|
||||
|
||||
impl<'a> Compiler<'a> {
|
||||
@ -23,7 +22,6 @@ impl<'a> Compiler<'a> {
|
||||
pub fn compile(
|
||||
&self,
|
||||
schema_id: &str,
|
||||
stem_path: Option<&str>,
|
||||
filter_keys: &[String],
|
||||
) -> Result<String, String> {
|
||||
let schema = self
|
||||
@ -32,32 +30,11 @@ impl<'a> Compiler<'a> {
|
||||
.get(schema_id)
|
||||
.ok_or_else(|| format!("Schema not found: {}", schema_id))?;
|
||||
|
||||
let target_schema = if let Some(path) = stem_path.filter(|p| !p.is_empty() && *p != "/") {
|
||||
if let Some(stems_map) = self.db.stems.get(schema_id) {
|
||||
if let Some(stem) = stems_map.get(path) {
|
||||
stem.schema.clone()
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Stem entity type '{}' not found in schema '{}'",
|
||||
path, schema_id
|
||||
));
|
||||
}
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Stem entity type '{}' not found in schema '{}'",
|
||||
path, schema_id
|
||||
));
|
||||
}
|
||||
} else {
|
||||
std::sync::Arc::new(schema.clone())
|
||||
};
|
||||
|
||||
let is_stem_query = stem_path.is_some();
|
||||
let target_schema = std::sync::Arc::new(schema.clone());
|
||||
|
||||
let mut compiler = Compiler {
|
||||
db: &self.db,
|
||||
filter_keys,
|
||||
is_stem_query,
|
||||
alias_counter: 0,
|
||||
};
|
||||
|
||||
@ -68,7 +45,7 @@ impl<'a> Compiler<'a> {
|
||||
parent_type: None,
|
||||
property_name: None,
|
||||
depth: 0,
|
||||
stem_path: String::new(),
|
||||
ast_path: String::new(),
|
||||
};
|
||||
|
||||
let (sql, _) = compiler.compile_node(node)?;
|
||||
@ -89,24 +66,24 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
fn compile_array(&mut self, node: Node<'a>) -> Result<(String, String), String> {
|
||||
if let Some(items) = &node.schema.obj.items {
|
||||
let next_path = if node.stem_path.is_empty() {
|
||||
let next_path = if node.ast_path.is_empty() {
|
||||
String::from("#")
|
||||
} else {
|
||||
format!("{}.#", node.stem_path)
|
||||
format!("{}.#", node.ast_path)
|
||||
};
|
||||
|
||||
if let Some(ref_id) = &items.obj.r#ref {
|
||||
if let Some(type_def) = self.db.types.get(ref_id) {
|
||||
let mut entity_noke = node.clone();
|
||||
entity_noke.stem_path = next_path;
|
||||
entity_noke.schema = std::sync::Arc::clone(items);
|
||||
return self.compile_entity(type_def, entity_noke, true);
|
||||
let mut entity_node = node.clone();
|
||||
entity_node.ast_path = next_path;
|
||||
entity_node.schema = std::sync::Arc::clone(items);
|
||||
return self.compile_entity(type_def, entity_node, true);
|
||||
}
|
||||
}
|
||||
|
||||
let mut next_node = node.clone();
|
||||
next_node.depth += 1;
|
||||
next_node.stem_path = next_path;
|
||||
next_node.ast_path = next_path;
|
||||
next_node.schema = std::sync::Arc::clone(items);
|
||||
let (item_sql, _) = self.compile_node(next_node)?;
|
||||
return Ok((
|
||||
@ -328,16 +305,16 @@ impl<'a> Compiler<'a> {
|
||||
) -> Result<(String, String), String> {
|
||||
let mut build_args = Vec::new();
|
||||
for (k, v) in props {
|
||||
let next_path = if node.stem_path.is_empty() {
|
||||
let next_path = if node.ast_path.is_empty() {
|
||||
k.clone()
|
||||
} else {
|
||||
format!("{}.{}", node.stem_path, k)
|
||||
format!("{}.{}", node.ast_path, k)
|
||||
};
|
||||
|
||||
let mut child_node = node.clone();
|
||||
child_node.property_name = Some(k.clone());
|
||||
child_node.depth += 1;
|
||||
child_node.stem_path = next_path;
|
||||
child_node.ast_path = next_path;
|
||||
child_node.schema = std::sync::Arc::clone(v);
|
||||
|
||||
let (child_sql, val_type) = self.compile_node(child_node)?;
|
||||
@ -479,13 +456,13 @@ impl<'a> Compiler<'a> {
|
||||
child_node.parent_type = Some(r#type);
|
||||
child_node.property_name = Some(prop_key.clone());
|
||||
child_node.depth += 1;
|
||||
let next_path = if node.stem_path.is_empty() {
|
||||
let next_path = if node.ast_path.is_empty() {
|
||||
prop_key.clone()
|
||||
} else {
|
||||
format!("{}.{}", node.stem_path, prop_key)
|
||||
format!("{}.{}", node.ast_path, prop_key)
|
||||
};
|
||||
|
||||
child_node.stem_path = next_path;
|
||||
child_node.ast_path = next_path;
|
||||
child_node.schema = std::sync::Arc::clone(prop_schema);
|
||||
|
||||
let (val_sql, val_type) = self.compile_node(child_node)?;
|
||||
@ -593,13 +570,13 @@ impl<'a> Compiler<'a> {
|
||||
let full_field_path = parts.next().unwrap_or(filter_key);
|
||||
let op = parts.next().unwrap_or("$eq");
|
||||
|
||||
let field_name = if node.stem_path.is_empty() {
|
||||
let field_name = if node.ast_path.is_empty() {
|
||||
if full_field_path.contains('.') || full_field_path.contains('#') {
|
||||
continue;
|
||||
}
|
||||
full_field_path
|
||||
} else {
|
||||
let prefix = format!("{}.", node.stem_path);
|
||||
let prefix = format!("{}.", node.ast_path);
|
||||
if full_field_path.starts_with(&prefix) {
|
||||
let remainder = &full_field_path[prefix.len()..];
|
||||
if remainder.contains('.') || remainder.contains('#') {
|
||||
|
||||
Reference in New Issue
Block a user