2022-12-18 10:23:07 +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-18 10:23:07 +00:00
|
|
|
use surrealdb::sql::Value;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn clear_transaction_cache_table() -> Result<(), Error> {
|
|
|
|
let sql = "
|
|
|
|
BEGIN;
|
|
|
|
CREATE person:one CONTENT { x: 0 };
|
|
|
|
SELECT * FROM person;
|
|
|
|
DEFINE TABLE other AS SELECT * FROM person;
|
|
|
|
COMMIT;
|
|
|
|
SELECT * FROM other;
|
|
|
|
";
|
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-18 10:23:07 +00:00
|
|
|
assert_eq!(res.len(), 4);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:one,
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:one,
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result;
|
|
|
|
assert!(tmp.is_ok());
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: other:one,
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn clear_transaction_cache_field() -> Result<(), Error> {
|
|
|
|
let sql = "
|
2023-04-25 10:13:04 +00:00
|
|
|
DEFINE FIELD test ON person TYPE option<string> VALUE 'test';
|
2022-12-18 10:23:07 +00:00
|
|
|
BEGIN;
|
2024-06-12 09:15:09 +00:00
|
|
|
UPSERT person:one CONTENT { x: 0 };
|
2022-12-18 10:23:07 +00:00
|
|
|
SELECT * FROM person;
|
|
|
|
REMOVE FIELD test ON person;
|
2024-06-12 09:15:09 +00:00
|
|
|
UPSERT person:two CONTENT { x: 0 };
|
2022-12-18 10:23:07 +00:00
|
|
|
SELECT * FROM person;
|
|
|
|
COMMIT;
|
|
|
|
";
|
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-18 10:23:07 +00:00
|
|
|
assert_eq!(res.len(), 6);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result;
|
2023-06-19 18:41:13 +00:00
|
|
|
assert!(tmp.is_ok(), "{:?}", tmp.err());
|
2022-12-18 10:23:07 +00:00
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:one,
|
|
|
|
test: 'test',
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:one,
|
|
|
|
test: 'test',
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result;
|
|
|
|
assert!(tmp.is_ok());
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:two,
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
let tmp = res.remove(0).result?;
|
|
|
|
let val = Value::parse(
|
|
|
|
"[
|
|
|
|
{
|
|
|
|
id: person:one,
|
|
|
|
test: 'test',
|
|
|
|
x: 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: person:two,
|
|
|
|
x: 0
|
|
|
|
}
|
|
|
|
]",
|
|
|
|
);
|
|
|
|
assert_eq!(tmp, val);
|
|
|
|
//
|
|
|
|
Ok(())
|
|
|
|
}
|