2022-12-04 22:07:43 +00:00
|
|
|
mod parse;
|
|
|
|
use parse::Parse;
|
2023-08-30 18:01:30 +00:00
|
|
|
mod helpers;
|
|
|
|
use helpers::new_ds;
|
2022-12-30 08:23:19 +00:00
|
|
|
use surrealdb::dbs::Session;
|
|
|
|
use surrealdb::err::Error;
|
2022-12-04 22:07:43 +00:00
|
|
|
use surrealdb::sql::Value;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn relate_with_parameters() -> Result<(), Error> {
|
|
|
|
let sql = "
|
|
|
|
LET $tobie = person:tobie;
|
|
|
|
LET $jaime = person:jaime;
|
2023-08-24 08:19:19 +00:00
|
|
|
RELATE $tobie->knows->$jaime SET id = knows:test, brother = true;
|
2022-12-04 22:07:43 +00:00
|
|
|
";
|
2023-08-30 18:01:30 +00:00
|
|
|
let dbs = new_ds().await?;
|
2023-07-29 18:47:25 +00:00
|
|
|
let ses = Session::owner().with_ns("test").with_db("test");
|
2023-07-05 21:26:13 +00:00
|
|
|
let res = &mut dbs.execute(sql, &ses, None).await?;
|
2022-12-04 22:07:43 +00:00
|
|
|
assert_eq!(res.len(), 3);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::None;
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::None;
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: knows:test,
|
|
|
|
in: person:tobie,
|
|
|
|
out: person:jaime,
|
2023-08-24 08:19:19 +00:00
|
|
|
brother: true,
|
2022-12-04 22:07:43 +00:00
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-03-30 18:30:46 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn relate_and_overwrite() -> Result<(), Error> {
|
|
|
|
let sql = "
|
|
|
|
LET $tobie = person:tobie;
|
|
|
|
LET $jaime = person:jaime;
|
2023-08-24 08:19:19 +00:00
|
|
|
RELATE $tobie->knows->$jaime CONTENT { id: knows:test, brother: true };
|
2023-03-30 18:30:46 +00:00
|
|
|
UPDATE knows:test CONTENT { test: true };
|
|
|
|
SELECT * FROM knows:test;
|
|
|
|
";
|
2023-08-30 18:01:30 +00:00
|
|
|
let dbs = new_ds().await?;
|
2023-07-29 18:47:25 +00:00
|
|
|
let ses = Session::owner().with_ns("test").with_db("test");
|
2023-07-05 21:26:13 +00:00
|
|
|
let res = &mut dbs.execute(sql, &ses, None).await?;
|
2023-03-30 18:30:46 +00:00
|
|
|
assert_eq!(res.len(), 5);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::None;
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::None;
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: knows:test,
|
|
|
|
in: person:tobie,
|
|
|
|
out: person:jaime,
|
2023-08-24 08:19:19 +00:00
|
|
|
brother: true,
|
2023-03-30 18:30:46 +00:00
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: knows:test,
|
|
|
|
in: person:tobie,
|
|
|
|
out: person:jaime,
|
|
|
|
test: true,
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: knows:test,
|
|
|
|
in: person:tobie,
|
|
|
|
out: person:jaime,
|
|
|
|
test: true,
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
Ok(())
|
|
|
|
}
|