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 {
|
||||
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()) {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue