added limit 1 to arrays treated as a single value in schemas
This commit is contained in:
@ -240,7 +240,7 @@ impl<'a> Compiler<'a> {
|
||||
};
|
||||
|
||||
// 3. Build WHERE clauses
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node)?;
|
||||
let where_clauses = self.compile_where_clause(r#type, &table_aliases, node.clone())?;
|
||||
|
||||
let selection = if is_array {
|
||||
format!("COALESCE(jsonb_agg({}), '[]'::jsonb)", jsonb_obj_sql)
|
||||
@ -248,11 +248,38 @@ impl<'a> Compiler<'a> {
|
||||
jsonb_obj_sql
|
||||
};
|
||||
|
||||
let mut limit_clause = "";
|
||||
if !is_array {
|
||||
let is_reverse = if let Some(prop_ref) = &node.property_name {
|
||||
let prop = prop_ref.as_str();
|
||||
if let Some(parent_schema) = &node.parent_schema {
|
||||
if let Some(compiled_edges) = parent_schema.obj.compiled_edges.get() {
|
||||
if let Some(edge) = compiled_edges.get(prop) {
|
||||
!edge.forward
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if is_reverse {
|
||||
limit_clause = " LIMIT 1";
|
||||
}
|
||||
}
|
||||
|
||||
let full_sql = format!(
|
||||
"(SELECT {} FROM {} WHERE {})",
|
||||
"(SELECT {} FROM {} WHERE {}{})",
|
||||
selection,
|
||||
from_clauses.join(" "),
|
||||
where_clauses.join(" AND ")
|
||||
where_clauses.join(" AND "),
|
||||
limit_clause
|
||||
);
|
||||
|
||||
Ok((
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::database::Database;
|
||||
use crate::drop::{Drop, Error, ErrorDetails};
|
||||
use std::collections::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod compiler;
|
||||
@ -33,7 +33,7 @@ impl Queryer {
|
||||
Err(msg) => {
|
||||
return Drop::with_errors(vec![Error {
|
||||
code: "FILTER_PARSE_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), msg.clone()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -140,7 +140,7 @@ impl Queryer {
|
||||
}
|
||||
Err(e) => Err(Drop::with_errors(vec![Error {
|
||||
code: "QUERY_COMPILATION_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), e.clone()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -169,7 +169,7 @@ impl Queryer {
|
||||
}
|
||||
Ok(other) => Drop::with_errors(vec![Error {
|
||||
code: "QUERY_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), format!("Expected array from generic query, got: {:?}", other)),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
@ -181,7 +181,7 @@ impl Queryer {
|
||||
}]),
|
||||
Err(e) => Drop::with_errors(vec![Error {
|
||||
code: "QUERY_FAILED".to_string(),
|
||||
values: Some(HashMap::from([
|
||||
values: Some(IndexMap::from([
|
||||
("error".to_string(), e.to_string()),
|
||||
])),
|
||||
details: ErrorDetails {
|
||||
|
||||
Reference in New Issue
Block a user