gjson pathing for stem paths
This commit is contained in:
21
src/lib.rs
21
src/lib.rs
@ -112,7 +112,7 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
pub fn jspg_stems() -> JsonB {
|
||||
use serde_json::{Map, Value};
|
||||
use serde_json::Value;
|
||||
|
||||
let engine_opt = {
|
||||
let lock = GLOBAL_JSPG.read().unwrap();
|
||||
@ -121,9 +121,24 @@ pub fn jspg_stems() -> JsonB {
|
||||
|
||||
match engine_opt {
|
||||
Some(engine) => {
|
||||
JsonB(serde_json::to_value(&engine.database.stems).unwrap_or(Value::Object(Map::new())))
|
||||
let mut result_arr = Vec::new();
|
||||
for (schema_name, stems_map) in &engine.database.stems {
|
||||
let mut stems_arr = Vec::new();
|
||||
for (path_key, stem_arc) in stems_map {
|
||||
stems_arr.push(serde_json::json!({
|
||||
"path": path_key,
|
||||
"type": stem_arc.r#type,
|
||||
"relation": stem_arc.relation
|
||||
}));
|
||||
}
|
||||
result_arr.push(serde_json::json!({
|
||||
"schema": schema_name,
|
||||
"stems": stems_arr
|
||||
}));
|
||||
}
|
||||
JsonB(serde_json::to_value(result_arr).unwrap_or(Value::Array(Vec::new())))
|
||||
}
|
||||
None => JsonB(Value::Object(Map::new())),
|
||||
None => JsonB(Value::Array(Vec::new())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user