Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c18163961 | |||
| 0b241c5227 | |||
| 3736c9d8f0 | |||
| ccca9129b2 | |||
| 333fc69735 | |||
| b0fc6c12ef |
@ -70,6 +70,10 @@
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@ -181,6 +185,17 @@
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"uuid.condition": {
|
||||
"type": "condition",
|
||||
"properties": {
|
||||
"$eq": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,6 +259,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -258,6 +274,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -278,6 +295,7 @@
|
||||
"billing_address",
|
||||
"gender",
|
||||
"birth_date",
|
||||
"uuid_field",
|
||||
"tags",
|
||||
"ad_hoc",
|
||||
"$and",
|
||||
@ -325,6 +343,12 @@
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"uuid_field": {
|
||||
"type": [
|
||||
"uuid.condition",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"first_name": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
@ -396,6 +420,7 @@
|
||||
"string.condition": {},
|
||||
"integer.condition": {},
|
||||
"date.condition": {},
|
||||
"uuid.condition": {},
|
||||
"search": {},
|
||||
"search.filter": {
|
||||
"type": "filter",
|
||||
|
||||
@ -59,6 +59,17 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_counterparty_orders",
|
||||
"schemas": {
|
||||
"get_counterparty_orders.response": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "counterparty.order"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"enums": [],
|
||||
@ -734,6 +745,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"counterparty.order": {
|
||||
"type": "order",
|
||||
"properties": {
|
||||
"counterparty": {
|
||||
"family": "organization"
|
||||
}
|
||||
}
|
||||
},
|
||||
"light.order": {
|
||||
"type": "order",
|
||||
"properties": {
|
||||
@ -2332,6 +2351,92 @@
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Order select with nested polymorphic counterparty family relation",
|
||||
"action": "query",
|
||||
"schema_id": "get_counterparty_orders.response",
|
||||
"expect": {
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"((SELECT jsonb_strip_nulls((",
|
||||
" SELECT COALESCE(jsonb_agg(jsonb_build_object(",
|
||||
" 'id', order_1.id,",
|
||||
" 'type', order_1.type,",
|
||||
" 'archived', entity_2.archived,",
|
||||
" 'created_at', entity_2.created_at,",
|
||||
" 'total', order_1.total,",
|
||||
" 'customer_id', order_1.customer_id,",
|
||||
" 'counterparty', (",
|
||||
" SELECT CASE",
|
||||
" WHEN organization_3.type = 'bot' THEN ((",
|
||||
" SELECT jsonb_build_object(",
|
||||
" 'id', entity_7.id,",
|
||||
" 'type', entity_7.type,",
|
||||
" 'archived', entity_7.archived,",
|
||||
" 'created_at', entity_7.created_at,",
|
||||
" 'name', organization_6.name,",
|
||||
" 'token', bot_5.token,",
|
||||
" 'role', bot_5.role",
|
||||
" )",
|
||||
" FROM agreego.bot bot_5",
|
||||
" JOIN agreego.organization organization_6 ON organization_6.id = bot_5.id",
|
||||
" JOIN agreego.entity entity_7 ON entity_7.id = organization_6.id",
|
||||
" WHERE",
|
||||
" NOT entity_7.archived",
|
||||
" AND entity_7.id = entity_4.id",
|
||||
" ))",
|
||||
" WHEN organization_3.type = 'organization' THEN ((",
|
||||
" SELECT jsonb_build_object(",
|
||||
" 'id', entity_9.id,",
|
||||
" 'type', entity_9.type,",
|
||||
" 'archived', entity_9.archived,",
|
||||
" 'created_at', entity_9.created_at,",
|
||||
" 'name', organization_8.name",
|
||||
" )",
|
||||
" FROM agreego.organization organization_8",
|
||||
" JOIN agreego.entity entity_9 ON entity_9.id = organization_8.id",
|
||||
" WHERE",
|
||||
" NOT entity_9.archived",
|
||||
" AND entity_9.id = entity_4.id",
|
||||
" ))",
|
||||
" WHEN organization_3.type = 'person' THEN ((",
|
||||
" SELECT jsonb_build_object(",
|
||||
" 'id', entity_12.id,",
|
||||
" 'type', entity_12.type,",
|
||||
" 'archived', entity_12.archived,",
|
||||
" 'created_at', entity_12.created_at,",
|
||||
" 'name', organization_11.name,",
|
||||
" 'first_name', person_10.first_name,",
|
||||
" 'last_name', person_10.last_name,",
|
||||
" 'age', person_10.age",
|
||||
" )",
|
||||
" FROM agreego.person person_10",
|
||||
" JOIN agreego.organization organization_11 ON organization_11.id = person_10.id",
|
||||
" JOIN agreego.entity entity_12 ON entity_12.id = organization_11.id",
|
||||
" WHERE",
|
||||
" NOT entity_12.archived",
|
||||
" AND entity_12.id = entity_4.id",
|
||||
" ))",
|
||||
" ELSE NULL",
|
||||
" END",
|
||||
" FROM agreego.organization organization_3",
|
||||
" JOIN agreego.entity entity_4 ON entity_4.id = organization_3.id",
|
||||
" WHERE",
|
||||
" NOT entity_4.archived",
|
||||
" AND order_1.counterparty_id = entity_4.id",
|
||||
" )",
|
||||
" )), '[]'::jsonb)",
|
||||
" FROM agreego.order order_1",
|
||||
" JOIN agreego.entity entity_2 ON entity_2.id = order_1.id",
|
||||
" WHERE",
|
||||
" NOT entity_2.archived",
|
||||
" AND order_1.counterparty_type IN ('bot', 'organization', 'person')",
|
||||
"))))"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -141,6 +141,8 @@ impl Schema {
|
||||
if let Some(fmt) = &schema.obj.format {
|
||||
if fmt == "date-time" {
|
||||
return Some(vec!["date.condition".to_string()]);
|
||||
} else if fmt == "uuid" {
|
||||
return Some(vec!["uuid.condition".to_string()]);
|
||||
}
|
||||
}
|
||||
Some(vec!["string.condition".to_string()])
|
||||
|
||||
@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn compose(val: &mut Value, errors: &mut Vec<crate::drop::Error>) -> Result<(), String> {
|
||||
let _ = std::fs::write("/Users/awgneo/Repositories/thoughtpatterns/cellular/jspg/traits_debug_val.json", serde_json::to_string_pretty(val).unwrap());
|
||||
let mut traits = HashMap::new();
|
||||
let mut schemas = HashMap::new();
|
||||
|
||||
|
||||
@ -213,6 +213,7 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
let mut case_node = node.clone();
|
||||
case_node.parent_alias = base_alias.clone();
|
||||
case_node.property_name = None;
|
||||
let arc_aliases = std::sync::Arc::new(table_aliases.clone());
|
||||
case_node.parent_type_aliases = Some(arc_aliases);
|
||||
case_node.parent_type = Some(r#type);
|
||||
@ -602,7 +603,7 @@ impl<'a> Compiler<'a> {
|
||||
|
||||
if let Some(type_name) = bound_type_name {
|
||||
// Ensure this type actually exists
|
||||
if self.db.types.contains_key(&type_name) {
|
||||
if let Some(type_def) = self.db.types.get(&type_name) {
|
||||
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
||||
let mut poly_col = None;
|
||||
let mut table_to_alias = "";
|
||||
@ -620,7 +621,23 @@ impl<'a> Compiler<'a> {
|
||||
.get(table_to_alias)
|
||||
.or_else(|| type_aliases.get(&node.parent_alias))
|
||||
{
|
||||
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||
// DEBUG: See what variations we have for this type
|
||||
#[cfg(not(test))]
|
||||
pgrx::notice!("JSPG_POLY_BOUNDS: type={}, col={}, variations_len={}, variations={:?}", type_name, col, type_def.variations.len(), type_def.variations);
|
||||
|
||||
// Use IN clause with all variations to support inherited types.
|
||||
// e.g., "asset" has variations ["asset", "property", "unit", ...]
|
||||
// so target_type IN ('asset','property','unit') instead of = 'asset'
|
||||
if type_def.variations.len() > 1 {
|
||||
let quoted: Vec<String> = type_def.variations.iter()
|
||||
.map(|v| format!("'{}'", v))
|
||||
.collect();
|
||||
where_clauses.push(format!(
|
||||
"{}.{} IN ({})", alias, col, quoted.join(", ")
|
||||
));
|
||||
} else {
|
||||
where_clauses.push(format!("{}.{} = '{}'", alias, col, type_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,6 +50,10 @@ impl Queryer {
|
||||
Err(drop) => return drop,
|
||||
};
|
||||
|
||||
// DEBUG: Emit compiled SQL as a NOTICE for inspection
|
||||
#[cfg(not(test))]
|
||||
pgrx::notice!("JSPG_SQL[{}]: {}", schema_id, sql);
|
||||
|
||||
// 3. Execute via Database Executor
|
||||
self.execute_sql(schema_id, &sql, args)
|
||||
}
|
||||
|
||||
@ -1499,6 +1499,12 @@ fn test_queryer_0_14() {
|
||||
crate::tests::runner::run_test_case(&path, 0, 14).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_queryer_0_15() {
|
||||
let path = format!("{}/fixtures/queryer.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 15).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_polymorphism_0_0() {
|
||||
let path = format!("{}/fixtures/polymorphism.json", env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
Reference in New Issue
Block a user