Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 724a9e3e44 | |||
| 5b2feb5ea7 | |||
| 473b087d97 | |||
| 6d6745d95d | |||
| 146efaa2d9 | |||
| d0294eec3f |
29
src/lib.rs
29
src/lib.rs
@ -7,6 +7,9 @@ pg_module_magic!();
|
||||
#[cfg(test)]
|
||||
pub struct JsonB(pub serde_json::Value);
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct Json(pub serde_json::Value);
|
||||
|
||||
pub mod database;
|
||||
pub mod drop;
|
||||
pub mod jspg;
|
||||
@ -41,7 +44,7 @@ fn jspg_failure() -> JsonB {
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern(strict))]
|
||||
pub fn jspg_setup(database: JsonB) -> JsonB {
|
||||
pub fn jspg_setup(database: Json) -> Json {
|
||||
let (new_jspg, drop) = crate::jspg::Jspg::new(&database.0);
|
||||
let new_arc = Arc::new(new_jspg);
|
||||
|
||||
@ -51,7 +54,7 @@ pub fn jspg_setup(database: JsonB) -> JsonB {
|
||||
*lock = Some(new_arc);
|
||||
}
|
||||
|
||||
JsonB(serde_json::to_value(drop).unwrap())
|
||||
Json(serde_json::to_value(drop).unwrap())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
@ -71,6 +74,22 @@ pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
pub fn jspg_merge_ordered(schema_id: &str, data: Json) -> Json {
|
||||
let engine_opt = {
|
||||
let lock = GLOBAL_JSPG.read().unwrap();
|
||||
lock.clone()
|
||||
};
|
||||
|
||||
match engine_opt {
|
||||
Some(engine) => {
|
||||
let drop = engine.merger.merge(schema_id, data.0);
|
||||
Json(serde_json::to_value(drop).unwrap())
|
||||
}
|
||||
None => Json(jspg_failure().0),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
pub fn jspg_query(schema_id: &str, filter: Option<JsonB>) -> JsonB {
|
||||
let engine_opt = {
|
||||
@ -109,7 +128,7 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
pub fn jspg_database() -> JsonB {
|
||||
pub fn jspg_database() -> Json {
|
||||
let engine_opt = {
|
||||
let lock = GLOBAL_JSPG.read().unwrap();
|
||||
lock.clone()
|
||||
@ -120,9 +139,9 @@ pub fn jspg_database() -> JsonB {
|
||||
let database_json = serde_json::to_value(&engine.database)
|
||||
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()));
|
||||
let drop = crate::drop::Drop::success_with_val(database_json);
|
||||
JsonB(serde_json::to_value(drop).unwrap())
|
||||
Json(serde_json::to_value(drop).unwrap())
|
||||
}
|
||||
None => jspg_failure(),
|
||||
None => Json(jspg_failure().0),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ fn test_library_api() {
|
||||
]
|
||||
});
|
||||
|
||||
let cache_drop = jspg_setup(JsonB(db_json));
|
||||
let cache_drop = jspg_setup(Json(db_json));
|
||||
assert_eq!(
|
||||
cache_drop.0,
|
||||
json!({
|
||||
|
||||
Reference in New Issue
Block a user