Use complex Record IDs for IDs in foreign tables with GROUP BY clauses

This commit is contained in:
Tobie Morgan Hitchcock 2022-10-04 00:27:38 +01:00
parent 66b182ec7d
commit e13a4c7742
3 changed files with 12 additions and 9 deletions

View file

@ -69,10 +69,8 @@ impl<'a> Document<'a> {
group.iter().map(|v| v.compute(ctx, opt, txn, Some(&self.initial))), group.iter().map(|v| v.compute(ctx, opt, txn, Some(&self.initial))),
) )
.await? .await?
.iter() .into_iter()
.map(|v| format!("{}", v))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(" ")
.into(), .into(),
}; };
// Set the current record id // 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))), group.iter().map(|v| v.compute(ctx, opt, txn, Some(&self.current))),
) )
.await? .await?
.iter() .into_iter()
.map(|v| format!("{}", v))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(" ")
.into(), .into(),
}; };
// Check if a WHERE clause is specified // Check if a WHERE clause is specified

View file

@ -7,6 +7,7 @@ use crate::sql::number::integer;
use crate::sql::object::{object, Object}; use crate::sql::object::{object, Object};
use crate::sql::strand::Strand; use crate::sql::strand::Strand;
use crate::sql::uuid::Uuid; use crate::sql::uuid::Uuid;
use crate::sql::value::Value;
use nanoid::nanoid; use nanoid::nanoid;
use nom::branch::alt; use nom::branch::alt;
use nom::combinator::map; use nom::combinator::map;
@ -75,6 +76,12 @@ impl From<&str> for Id {
} }
} }
impl From<Vec<Value>> for Id {
fn from(v: Vec<Value>) -> Self {
Id::Array(v.into())
}
}
impl Id { impl Id {
pub fn rand() -> Id { pub fn rand() -> Id {
Id::String(nanoid!(20, &ID_CHARS)) Id::String(nanoid!(20, &ID_CHARS))

View file

@ -59,7 +59,7 @@ async fn define_foreign_table() -> Result<(), Error> {
age: 39, age: 39,
average: 70, average: 70,
count: 1, count: 1,
id: 'person_by_age:39', id: person_by_age:[39],
total: 39 total: 39
} }
]", ]",
@ -77,7 +77,7 @@ async fn define_foreign_table() -> Result<(), Error> {
age: 39, age: 39,
average: 75, average: 75,
count: 2, count: 2,
id: 'person_by_age:39', id: person_by_age:[39],
total: 78 total: 78
} }
]", ]",
@ -95,7 +95,7 @@ async fn define_foreign_table() -> Result<(), Error> {
age: 39, age: 39,
average: 80, average: 80,
count: 2, count: 2,
id: 'person_by_age:39', id: person_by_age:[39],
total: 78 total: 78
} }
]", ]",