Skip to content

Commit

Permalink
Added test case for parameter after fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Vignesh1-art committed May 28, 2024
1 parent cc20349 commit 160111e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/sql/value/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Value {
None => Ok(()),
},
Part::Value(f) => {
let x = stk.run(|stk|f.compute(stk, ctx, opt, txn, None)).await?;
let x = stk.run(|stk| f.compute(stk, ctx, opt, txn, None)).await?;
match x {
Value::Strand(s) => {
match v.get_mut(s.as_str()) {
Expand Down
52 changes: 51 additions & 1 deletion lib/tests/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ async fn create_relate_select() -> Result<(), Error> {
SELECT *, ->bought->product.* AS products FROM user;
SELECT *, ->bought AS products FROM user FETCH products;
SELECT *, ->(bought AS purchases) FROM user FETCH purchases, purchases.out;
LET $param1 = \"purchases\";
SELECT *, ->(bought AS purchases) FROM user FETCH $param1, purchases.out;
";
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(), 12);
assert_eq!(res.len(), 14);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
Expand Down Expand Up @@ -277,5 +279,53 @@ async fn create_relate_select() -> Result<(), Error> {
);
assert_eq!(tmp, val);
//
// Remove LET statement result
res.remove(0);
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: user:jaime,
name: 'Jaime',
purchases: [
{
id: bought:3,
in: user:jaime,
out: {
id: product:laptop,
price: 3000
},
payment_method: 'VISA'
}
]
},
{
id: user:tobie,
name: 'Tobie',
purchases: [
{
id: bought:1,
in: user:tobie,
out: {
id: product:phone,
price: 1000
},
payment_method: 'VISA'
},
{
id: bought:2,
in: user:tobie,
out: {
id: product:laptop,
price: 3000
},
payment_method: 'VISA'
}
]
}
]",
);
assert_eq!(tmp, val);
//
Ok(())
}

0 comments on commit 160111e

Please sign in to comment.