Compute ID in create statement (#4468)
Co-authored-by: Emmanuel Keller <emmanuel.keller@surrealdb.com> Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
6d4176549d
commit
687c8b662e
2 changed files with 16 additions and 4 deletions
|
@ -44,17 +44,17 @@ impl Data {
|
||||||
match self {
|
match self {
|
||||||
Self::MergeExpression(v) => match v {
|
Self::MergeExpression(v) => match v {
|
||||||
Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()),
|
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),
|
_ => Ok(None),
|
||||||
},
|
},
|
||||||
Self::ReplaceExpression(v) => match v {
|
Self::ReplaceExpression(v) => match v {
|
||||||
Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()),
|
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),
|
_ => Ok(None),
|
||||||
},
|
},
|
||||||
Self::ContentExpression(v) => match v {
|
Self::ContentExpression(v) => match v {
|
||||||
Value::Param(v) => Ok(v.compute(stk, ctx, opt, None).await?.rid().some()),
|
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),
|
_ => Ok(None),
|
||||||
},
|
},
|
||||||
Self::SetExpression(v) => match v.iter().find(|f| f.0.is_id()) {
|
Self::SetExpression(v) => match v.iter().find(|f| f.0.is_id()) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ async fn create_with_id() -> Result<(), Error> {
|
||||||
CREATE test CONTENT { id: other:715917898417176677 };
|
CREATE test CONTENT { id: other:715917898417176677 };
|
||||||
CREATE test CONTENT { id: other:⟨715917898.417176677⟩ };
|
CREATE test CONTENT { id: other:⟨715917898.417176677⟩ };
|
||||||
CREATE test CONTENT { id: other:9223372036854775808 };
|
CREATE test CONTENT { id: other:9223372036854775808 };
|
||||||
|
CREATE person CONTENT { id: type::string(8), name: 'Tester' };
|
||||||
-- Should error as id is empty
|
-- Should error as id is empty
|
||||||
CREATE person SET id = '';
|
CREATE person SET id = '';
|
||||||
CREATE person CONTENT { id: '', name: 'Tester' };
|
CREATE person CONTENT { id: '', name: 'Tester' };
|
||||||
|
@ -33,7 +34,7 @@ async fn create_with_id() -> Result<(), Error> {
|
||||||
let dbs = new_ds().await?;
|
let dbs = new_ds().await?;
|
||||||
let ses = Session::owner().with_ns("test").with_db("test");
|
let ses = Session::owner().with_ns("test").with_db("test");
|
||||||
let res = &mut dbs.execute(sql, &ses, None).await?;
|
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 tmp = res.remove(0).result?;
|
||||||
let val = Value::parse(
|
let val = Value::parse(
|
||||||
|
@ -142,6 +143,17 @@ async fn create_with_id() -> Result<(), Error> {
|
||||||
);
|
);
|
||||||
assert_eq!(tmp, val);
|
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;
|
let tmp = res.remove(0).result;
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
tmp.err(),
|
tmp.err(),
|
||||||
|
|
Loading…
Reference in a new issue