2022-09-29 10:09:20 +00:00
|
|
|
mod parse;
|
|
|
|
use parse::Parse;
|
2022-12-30 08:23:19 +00:00
|
|
|
use surrealdb::dbs::Session;
|
|
|
|
use surrealdb::err::Error;
|
|
|
|
use surrealdb::kvs::Datastore;
|
2022-09-29 10:09:20 +00:00
|
|
|
use surrealdb::sql::Value;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn merge_record() -> Result<(), Error> {
|
|
|
|
let sql = "
|
|
|
|
UPDATE person:test SET name.initials = 'TMH', name.first = 'Tobie', name.last = 'Morgan Hitchcock';
|
|
|
|
UPDATE person:test MERGE {
|
|
|
|
name: {
|
|
|
|
title: 'Mr',
|
|
|
|
initials: NONE,
|
|
|
|
suffix: ['BSc', 'MSc'],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
";
|
|
|
|
let dbs = Datastore::new("memory").await?;
|
|
|
|
let ses = Session::for_kv().with_ns("test").with_db("test");
|
2023-07-05 21:26:13 +00:00
|
|
|
let res = &mut dbs.execute(sql, &ses, None).await?;
|
2022-09-29 10:09:20 +00:00
|
|
|
assert_eq!(res.len(), 2);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:test,
|
|
|
|
name: {
|
|
|
|
initials: 'TMH',
|
|
|
|
first: 'Tobie',
|
|
|
|
last: 'Morgan Hitchcock',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:test,
|
|
|
|
name: {
|
|
|
|
title: 'Mr',
|
|
|
|
first: 'Tobie',
|
|
|
|
last: 'Morgan Hitchcock',
|
|
|
|
suffix: ['BSc', 'MSc'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
Ok(())
|
|
|
|
}
|