fixed more filtering issues and promoted enum condition generation
This commit is contained in:
87
src/database/compile/condition.rs
Normal file
87
src/database/compile/condition.rs
Normal file
@ -0,0 +1,87 @@
|
||||
use crate::database::object::{SchemaObject, SchemaTypeOrArray};
|
||||
use crate::database::schema::Schema;
|
||||
use crate::database::r#enum::Enum;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl Enum {
|
||||
pub fn compile_condition(&self) -> Schema {
|
||||
let mut props = BTreeMap::new();
|
||||
let enum_name = &self.name;
|
||||
|
||||
let mut eq_obj = SchemaObject::default();
|
||||
eq_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
|
||||
enum_name.clone(),
|
||||
"null".to_string(),
|
||||
]));
|
||||
props.insert(
|
||||
"$eq".to_string(),
|
||||
Arc::new(Schema {
|
||||
obj: eq_obj,
|
||||
always_fail: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let mut ne_obj = SchemaObject::default();
|
||||
ne_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
|
||||
enum_name.clone(),
|
||||
"null".to_string(),
|
||||
]));
|
||||
props.insert(
|
||||
"$ne".to_string(),
|
||||
Arc::new(Schema {
|
||||
obj: ne_obj,
|
||||
always_fail: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let mut of_obj = SchemaObject::default();
|
||||
of_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
|
||||
"array".to_string(),
|
||||
"null".to_string(),
|
||||
]));
|
||||
of_obj.items = Some(Arc::new(Schema {
|
||||
obj: SchemaObject {
|
||||
type_: Some(SchemaTypeOrArray::Single(enum_name.clone())),
|
||||
..Default::default()
|
||||
},
|
||||
always_fail: false,
|
||||
}));
|
||||
props.insert(
|
||||
"$of".to_string(),
|
||||
Arc::new(Schema {
|
||||
obj: of_obj,
|
||||
always_fail: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let mut nof_obj = SchemaObject::default();
|
||||
nof_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
|
||||
"array".to_string(),
|
||||
"null".to_string(),
|
||||
]));
|
||||
nof_obj.items = Some(Arc::new(Schema {
|
||||
obj: SchemaObject {
|
||||
type_: Some(SchemaTypeOrArray::Single(enum_name.clone())),
|
||||
..Default::default()
|
||||
},
|
||||
always_fail: false,
|
||||
}));
|
||||
props.insert(
|
||||
"$nof".to_string(),
|
||||
Arc::new(Schema {
|
||||
obj: nof_obj,
|
||||
always_fail: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let mut cond_obj = SchemaObject::default();
|
||||
cond_obj.type_ = Some(SchemaTypeOrArray::Single("condition".to_string()));
|
||||
cond_obj.properties = Some(props);
|
||||
|
||||
Schema {
|
||||
obj: cond_obj,
|
||||
always_fail: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user