Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ serde_json = "1.0"
uuid = { version = "1.8.0", features = ["v7", "serde"] }
chrono = { version = "0.4.43", features = ["serde"] }
jsonb = "0.5.5"
jsonpath-rust = "0.7"
jsonpath-rust = "1.0"
tokio = { version = "1.49.0", features = ["full"] }
async-trait = "0.1.89"
futures = "0.3.31"
Expand Down
20 changes: 7 additions & 13 deletions src/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::db::DB;
use jsonpath_rust::JsonPath;
use jsonpath_rust::query::js_path_vals;
use serde_json::Value;
use std::cmp::Ordering;
use std::str::FromStr;

use tracing::{Level, span};

Expand Down Expand Up @@ -218,18 +217,13 @@ fn evaluate_expression(expr: &Expression, doc: &Value) -> Value {
match expr {
Expression::FieldReference(path) => get_path(doc, path).unwrap_or(Value::Null),
Expression::JsonPath(path) => {
if let Ok(p) = JsonPath::from_str(path) {
let inst = p.find(doc);
if let Some(arr) = inst.as_array() {
if arr.is_empty() {
Value::Null
} else if arr.len() == 1 {
arr[0].clone()
} else {
inst.clone()
}
if let Ok(nodes) = js_path_vals(path, doc) {
if nodes.is_empty() {
Value::Null
} else if nodes.len() == 1 {
nodes[0].clone()
} else {
inst
Value::Array(nodes.into_iter().cloned().collect())
}
} else {
Value::Null
Expand Down