Skip to content

Commit d3659f5

Browse files
committed
fix(query): adapt to jsonpath-rust 1.0.4 trait changes
1 parent 732d678 commit d3659f5

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

src/query.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::db::DB;
2-
use jsonpath_rust::JsonPath;
2+
use jsonpath_rust::query::js_path_vals;
33
use serde_json::Value;
44
use std::cmp::Ordering;
5-
use std::str::FromStr;
65

76
use tracing::{Level, span};
87

@@ -218,18 +217,13 @@ fn evaluate_expression(expr: &Expression, doc: &Value) -> Value {
218217
match expr {
219218
Expression::FieldReference(path) => get_path(doc, path).unwrap_or(Value::Null),
220219
Expression::JsonPath(path) => {
221-
if let Ok(p) = JsonPath::from_str(path) {
222-
let inst = p.find(doc);
223-
if let Some(arr) = inst.as_array() {
224-
if arr.is_empty() {
225-
Value::Null
226-
} else if arr.len() == 1 {
227-
arr[0].clone()
228-
} else {
229-
inst.clone()
230-
}
220+
if let Ok(nodes) = js_path_vals(path, doc) {
221+
if nodes.is_empty() {
222+
Value::Null
223+
} else if nodes.len() == 1 {
224+
nodes[0].clone()
231225
} else {
232-
inst
226+
Value::Array(nodes.into_iter().cloned().collect())
233227
}
234228
} else {
235229
Value::Null

0 commit comments

Comments
 (0)