From a687a7f4bff95bdfbd962cef8244716482ff69fc Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 15 Jun 2022 08:48:27 +0100 Subject: [PATCH] Ensure remote records in FETCH clauses are fetched correctly --- lib/src/dbs/iterator.rs | 2 +- lib/src/sql/part.rs | 2 ++ lib/src/sql/value/get.rs | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/src/dbs/iterator.rs b/lib/src/dbs/iterator.rs index 97fe77d8..1d98db5c 100644 --- a/lib/src/dbs/iterator.rs +++ b/lib/src/dbs/iterator.rs @@ -307,7 +307,7 @@ impl Iterator { match val { Value::Array(v) => { // Fetch all remote records - let val = Value::Array(v).get(ctx, opt, txn, &[Part::All]).await?; + let val = Value::Array(v).get(ctx, opt, txn, &[Part::Any]).await?; // Set the value at the path obj.set(ctx, opt, txn, fetch, val).await?; } diff --git a/lib/src/sql/part.rs b/lib/src/sql/part.rs index f3863c60..d20ff0e7 100644 --- a/lib/src/sql/part.rs +++ b/lib/src/sql/part.rs @@ -17,6 +17,7 @@ use std::str; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] pub enum Part { + Any, All, Last, First, @@ -103,6 +104,7 @@ impl Part { impl fmt::Display for Part { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + Part::Any => write!(f, ".."), Part::All => write!(f, "[*]"), Part::Last => write!(f, "[$]"), Part::First => write!(f, "[0]"), diff --git a/lib/src/sql/value/get.rs b/lib/src/sql/value/get.rs index bee0560d..11ad7056 100644 --- a/lib/src/sql/value/get.rs +++ b/lib/src/sql/value/get.rs @@ -38,6 +38,7 @@ impl Value { None => Ok(Value::None), }, Part::All => self.get(ctx, opt, txn, path.next()).await, + Part::Any => self.get(ctx, opt, txn, path.next()).await, _ => Ok(Value::None), }, // Current path part is an array @@ -47,6 +48,10 @@ impl Value { let futs = v.iter().map(|v| v.get(ctx, opt, txn, path)); try_join_all(futs).await.map(|v| v.into()) } + Part::Any => { + let futs = v.iter().map(|v| v.get(ctx, opt, txn, path)); + try_join_all(futs).await.map(|v| v.into()) + } Part::First => match v.first() { Some(v) => v.get(ctx, opt, txn, path.next()).await, None => Ok(Value::None), @@ -132,7 +137,13 @@ impl Value { } } // Ignore everything else - _ => Ok(Value::None), + _ => match p { + Part::Any => match path.len() { + 1 => Ok(self.clone()), + _ => Ok(Value::None), + }, + _ => Ok(Value::None), + }, }, // No more parts so get the value None => Ok(self.clone()),