42 lines
882 B
Rust
42 lines
882 B
Rust
|
mod parse;
|
||
|
use parse::Parse;
|
||
|
use surrealdb::sql::Value;
|
||
|
use surrealdb::Datastore;
|
||
|
use surrealdb::Error;
|
||
|
use surrealdb::Session;
|
||
|
|
||
|
#[tokio::test]
|
||
|
async fn relate_with_parameters() -> Result<(), Error> {
|
||
|
let sql = "
|
||
|
LET $tobie = person:tobie;
|
||
|
LET $jaime = person:jaime;
|
||
|
RELATE $tobie->knows->$jaime SET id = knows:test;
|
||
|
";
|
||
|
let dbs = Datastore::new("memory").await?;
|
||
|
let ses = Session::for_kv().with_ns("test").with_db("test");
|
||
|
let res = &mut dbs.execute(&sql, &ses, None, false).await?;
|
||
|
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,
|
||
|
}
|
||
|
]",
|
||
|
);
|
||
|
assert_eq!(tmp, val);
|
||
|
//
|
||
|
Ok(())
|
||
|
}
|