more filter fixes
This commit is contained in:
@ -94,19 +94,30 @@
|
||||
{
|
||||
"id": "type3",
|
||||
"type": "type",
|
||||
"name": "filter",
|
||||
"name": "search",
|
||||
"module": "core",
|
||||
"source": "filter",
|
||||
"source": "search",
|
||||
"hierarchy": [
|
||||
"filter"
|
||||
"search"
|
||||
],
|
||||
"variations": [
|
||||
"filter",
|
||||
"string.condition",
|
||||
"integer.condition",
|
||||
"date.condition"
|
||||
"search"
|
||||
],
|
||||
"schemas": {
|
||||
"search": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"filter": {
|
||||
"type": "filter"
|
||||
}
|
||||
}
|
||||
},
|
||||
"filter": {
|
||||
"type": "object"
|
||||
},
|
||||
"condition": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -161,7 +172,7 @@
|
||||
"schemas": {
|
||||
"person": {},
|
||||
"person.filter": {
|
||||
"type": "object",
|
||||
"type": "filter",
|
||||
"compiledPropertyNames": [
|
||||
"age",
|
||||
"billing_address",
|
||||
@ -197,7 +208,7 @@
|
||||
},
|
||||
"address": {},
|
||||
"address.filter": {
|
||||
"type": "object",
|
||||
"type": "filter",
|
||||
"compiledPropertyNames": [
|
||||
"city"
|
||||
],
|
||||
@ -210,10 +221,33 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"filter": {},
|
||||
"condition": {},
|
||||
"string.condition": {},
|
||||
"integer.condition": {},
|
||||
"date.condition": {}
|
||||
"date.condition": {},
|
||||
"search": {},
|
||||
"search.filter": {
|
||||
"type": "filter",
|
||||
"compiledPropertyNames": [
|
||||
"filter",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": [
|
||||
"filter.filter",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"type": [
|
||||
"string.condition",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1195,7 +1195,7 @@
|
||||
"description": "Simple entity select with multiple filters",
|
||||
"action": "query",
|
||||
"schema_id": "entity",
|
||||
"filters": {
|
||||
"filter": {
|
||||
"id": {
|
||||
"$eq": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"$ne": "123e4567-e89b-12d3-a456-426614174001",
|
||||
@ -1443,7 +1443,7 @@
|
||||
"description": "Person select on full schema with filters",
|
||||
"action": "query",
|
||||
"schema_id": "full.person",
|
||||
"filters": {
|
||||
"filter": {
|
||||
"age": {
|
||||
"$eq": 30,
|
||||
"$gt": 20,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::database::Database;
|
||||
use crate::database::object::{SchemaObject, SchemaTypeOrArray};
|
||||
use crate::database::schema::Schema;
|
||||
use crate::database::Database;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
@ -20,16 +20,26 @@ impl Schema {
|
||||
let mut child_obj = SchemaObject::default();
|
||||
child_obj.type_ = Some(SchemaTypeOrArray::Multiple(filter_type));
|
||||
|
||||
filter_props.insert(key.clone(), Arc::new(Schema { obj: child_obj, always_fail: false }));
|
||||
filter_props.insert(
|
||||
key.clone(),
|
||||
Arc::new(Schema {
|
||||
obj: child_obj,
|
||||
always_fail: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if !filter_props.is_empty() {
|
||||
let mut wrapper_obj = SchemaObject::default();
|
||||
wrapper_obj.type_ = Some(SchemaTypeOrArray::Single("object".to_string()));
|
||||
// Conceptually link this directly into the STI lineage of the base `filter` object
|
||||
wrapper_obj.type_ = Some(SchemaTypeOrArray::Single("filter".to_string()));
|
||||
wrapper_obj.properties = Some(filter_props);
|
||||
|
||||
return Some(Schema { obj: wrapper_obj, always_fail: false });
|
||||
return Some(Schema {
|
||||
obj: wrapper_obj,
|
||||
always_fail: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
@ -1,6 +1,6 @@
|
||||
pub mod collection;
|
||||
pub mod edges;
|
||||
pub mod filters;
|
||||
pub mod filter;
|
||||
pub mod polymorphism;
|
||||
|
||||
use crate::database::schema::Schema;
|
||||
|
||||
@ -15,6 +15,7 @@ pub struct Punc {
|
||||
pub public: bool,
|
||||
pub form: bool,
|
||||
pub get: Option<String>,
|
||||
pub save: Option<String>,
|
||||
pub page: Option<Page>,
|
||||
#[serde(default)]
|
||||
pub schemas: std::collections::BTreeMap<String, Arc<Schema>>,
|
||||
|
||||
@ -3,6 +3,8 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Relation {
|
||||
pub id: String,
|
||||
pub r#type: String,
|
||||
pub constraint: String,
|
||||
pub source_type: String,
|
||||
pub source_columns: Vec<String>,
|
||||
|
||||
@ -72,7 +72,7 @@ pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
pub fn jspg_query(schema_id: &str, filters: Option<JsonB>) -> JsonB {
|
||||
pub fn jspg_query(schema_id: &str, filter: Option<JsonB>) -> JsonB {
|
||||
let engine_opt = {
|
||||
let lock = GLOBAL_JSPG.read().unwrap();
|
||||
lock.clone()
|
||||
@ -82,7 +82,7 @@ pub fn jspg_query(schema_id: &str, filters: Option<JsonB>) -> JsonB {
|
||||
Some(engine) => {
|
||||
let drop = engine
|
||||
.queryer
|
||||
.query(schema_id, filters.as_ref().map(|f| &f.0));
|
||||
.query(schema_id, filter.as_ref().map(|f| &f.0));
|
||||
JsonB(serde_json::to_value(drop).unwrap())
|
||||
}
|
||||
None => jspg_failure(),
|
||||
|
||||
@ -21,9 +21,9 @@ impl Queryer {
|
||||
pub fn query(
|
||||
&self,
|
||||
schema_id: &str,
|
||||
filters: Option<&serde_json::Value>,
|
||||
filter: Option<&serde_json::Value>,
|
||||
) -> crate::drop::Drop {
|
||||
let filters_map = filters.and_then(|f| f.as_object());
|
||||
let filters_map = filter.and_then(|f| f.as_object());
|
||||
|
||||
// 1. Process filters into structured $op keys and linear values
|
||||
let (filter_keys, args) = match self.parse_filter_entries(filters_map) {
|
||||
@ -35,7 +35,7 @@ impl Queryer {
|
||||
details: crate::drop::ErrorDetails {
|
||||
path: None, // filters apply to the root query
|
||||
cause: Some(msg),
|
||||
context: filters.cloned(),
|
||||
context: filter.cloned(),
|
||||
schema: Some(schema_id.to_string()),
|
||||
},
|
||||
}]);
|
||||
|
||||
@ -92,6 +92,8 @@ fn test_library_api() {
|
||||
"puncs": {},
|
||||
"relations": {
|
||||
"fk_test_target": {
|
||||
"id": "11111111-1111-1111-1111-111111111111",
|
||||
"type": "relation",
|
||||
"constraint": "fk_test_target",
|
||||
"destination_columns": ["id"],
|
||||
"destination_type": "target_schema",
|
||||
@ -144,7 +146,7 @@ fn test_library_api() {
|
||||
"target": { "type": ["target_schema.filter", "null"] },
|
||||
"type": { "type": ["string.condition", "null"] }
|
||||
},
|
||||
"type": "object"
|
||||
"type": "filter"
|
||||
}
|
||||
},
|
||||
"sensitive": false,
|
||||
@ -181,7 +183,7 @@ fn test_library_api() {
|
||||
"properties": {
|
||||
"value": { "type": ["number.condition", "null"] }
|
||||
},
|
||||
"type": "object"
|
||||
"type": "filter"
|
||||
}
|
||||
},
|
||||
"sensitive": false,
|
||||
|
||||
@ -17,7 +17,7 @@ pub struct Case {
|
||||
|
||||
// For Query
|
||||
#[serde(default)]
|
||||
pub filters: Option<serde_json::Value>,
|
||||
pub filter: Option<serde_json::Value>,
|
||||
|
||||
// For Merge & Validate
|
||||
#[serde(default)]
|
||||
@ -122,7 +122,7 @@ impl Case {
|
||||
use crate::queryer::Queryer;
|
||||
let queryer = Queryer::new(db.clone());
|
||||
|
||||
let result = queryer.query(&self.schema_id, self.filters.as_ref());
|
||||
let result = queryer.query(&self.schema_id, self.filter.as_ref());
|
||||
|
||||
let return_val = if let Some(expect) = &self.expect {
|
||||
if let Err(e) = expect.assert_drop(&result) {
|
||||
|
||||
Reference in New Issue
Block a user