From 687c8b662e0bed3370f905911c5ec939fd75b7a2 Mon Sep 17 00:00:00 2001 From: Dmitrii Blaginin Date: Fri, 23 Aug 2024 16:55:23 +0100 Subject: [PATCH] Compute ID in create statement (#4468) Co-authored-by: Emmanuel Keller Co-authored-by: Tobie Morgan Hitchcock --- core/src/sql/data.rs | 6 +++--- sdk/tests/create.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/src/sql/data.rs b/core/src/sql/data.rs index d9a35b48..183295af 100644 --- a/core/src/sql/data.rs +++ b/core/src/sql/data.rs @@ -44,17 +44,17 @@ impl Data { match self { Self::MergeExpression(v) => match v { Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()), - Value::Object(_) => Ok(v.rid().some()), + Value::Object(_) => Ok(v.rid().compute(stk, ctx, opt, None).await?.some()), _ => Ok(None), }, Self::ReplaceExpression(v) => match v { Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()), - Value::Object(_) => Ok(v.rid().some()), + Value::Object(_) => Ok(v.rid().compute(stk, ctx, opt, None).await?.some()), _ => Ok(None), }, Self::ContentExpression(v) => match v { Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()), - Value::Object(_) => Ok(v.rid().some()), + Value::Object(_) => Ok(v.rid().compute(stk, ctx, opt, None).await?.some()), _ => Ok(None), }, Self::SetExpression(v) => match v.iter().find(|f| f.0.is_id()) { diff --git a/sdk/tests/create.rs b/sdk/tests/create.rs index f89bd98a..f7cbd537 100644 --- a/sdk/tests/create.rs +++ b/sdk/tests/create.rs @@ -23,6 +23,7 @@ async fn create_with_id() -> Result<(), Error> { CREATE test CONTENT { id: other:715917898417176677 }; CREATE test CONTENT { id: other:⟨715917898.417176677⟩ }; CREATE test CONTENT { id: other:9223372036854775808 }; + CREATE person CONTENT { id: type::string(8), name: 'Tester' }; -- Should error as id is empty CREATE person SET id = ''; CREATE person CONTENT { id: '', name: 'Tester' }; @@ -33,7 +34,7 @@ async fn create_with_id() -> Result<(), Error> { let dbs = new_ds().await?; let ses = Session::owner().with_ns("test").with_db("test"); let res = &mut dbs.execute(sql, &ses, None).await?; - assert_eq!(res.len(), 14); + assert_eq!(res.len(), 15); // let tmp = res.remove(0).result?; let val = Value::parse( @@ -142,6 +143,17 @@ async fn create_with_id() -> Result<(), Error> { ); assert_eq!(tmp, val); // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: person:⟨8⟩, + name: 'Tester' + } + ]", + ); + assert_eq!(tmp, val); + // let tmp = res.remove(0).result; assert!(matches!( tmp.err(),