From e13a4c7742c37b7bc0efa2f4b35349105836d79c Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 4 Oct 2022 00:27:38 +0100 Subject: [PATCH] Use complex Record IDs for IDs in foreign tables with GROUP BY clauses --- lib/src/doc/table.rs | 8 ++------ lib/src/sql/id.rs | 7 +++++++ lib/tests/table.rs | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/src/doc/table.rs b/lib/src/doc/table.rs index 97e3bfb2..83cb7bb4 100644 --- a/lib/src/doc/table.rs +++ b/lib/src/doc/table.rs @@ -69,10 +69,8 @@ impl<'a> Document<'a> { group.iter().map(|v| v.compute(ctx, opt, txn, Some(&self.initial))), ) .await? - .iter() - .map(|v| format!("{}", v)) + .into_iter() .collect::>() - .join(" ") .into(), }; // Set the current record id @@ -82,10 +80,8 @@ impl<'a> Document<'a> { group.iter().map(|v| v.compute(ctx, opt, txn, Some(&self.current))), ) .await? - .iter() - .map(|v| format!("{}", v)) + .into_iter() .collect::>() - .join(" ") .into(), }; // Check if a WHERE clause is specified diff --git a/lib/src/sql/id.rs b/lib/src/sql/id.rs index a674ff57..5328b1f0 100644 --- a/lib/src/sql/id.rs +++ b/lib/src/sql/id.rs @@ -7,6 +7,7 @@ use crate::sql::number::integer; use crate::sql::object::{object, Object}; use crate::sql::strand::Strand; use crate::sql::uuid::Uuid; +use crate::sql::value::Value; use nanoid::nanoid; use nom::branch::alt; use nom::combinator::map; @@ -75,6 +76,12 @@ impl From<&str> for Id { } } +impl From> for Id { + fn from(v: Vec) -> Self { + Id::Array(v.into()) + } +} + impl Id { pub fn rand() -> Id { Id::String(nanoid!(20, &ID_CHARS)) diff --git a/lib/tests/table.rs b/lib/tests/table.rs index 168974c4..61d08bba 100644 --- a/lib/tests/table.rs +++ b/lib/tests/table.rs @@ -59,7 +59,7 @@ async fn define_foreign_table() -> Result<(), Error> { age: 39, average: 70, count: 1, - id: 'person_by_age:39', + id: person_by_age:[39], total: 39 } ]", @@ -77,7 +77,7 @@ async fn define_foreign_table() -> Result<(), Error> { age: 39, average: 75, count: 2, - id: 'person_by_age:39', + id: person_by_age:[39], total: 78 } ]", @@ -95,7 +95,7 @@ async fn define_foreign_table() -> Result<(), Error> { age: 39, average: 80, count: 2, - id: 'person_by_age:39', + id: person_by_age:[39], total: 78 } ]",