Process futures before using as function arguments

Closes #1538
This commit is contained in:
Tobie Morgan Hitchcock 2022-12-22 08:33:57 +00:00
parent 157f7c8abe
commit 1ce6c4bae6
2 changed files with 34 additions and 0 deletions

View file

@ -113,6 +113,8 @@ impl Function {
) -> Result<Value, Error> {
// Prevent long function chains
let opt = &opt.dive(1)?;
// Ensure futures are run
let opt = &opt.futures(true);
// Process the function type
match self {
Self::Cast(s, x) => {

View file

@ -33,3 +33,35 @@ async fn future_function_simple() -> Result<(), Error> {
//
Ok(())
}
#[tokio::test]
async fn future_function_arguments() -> Result<(), Error> {
let sql = "
UPDATE future:test SET
a = 'test@surrealdb.com',
b = <future> { 'test@surrealdb.com' },
x = 'a-' + parse::email::user(a),
y = 'b-' + parse::email::user(b)
;
";
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(), 1);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
a: 'test@surrealdb.com',
b: 'test@surrealdb.com',
id: 'future:test',
x: 'a-test',
y: 'b-test',
}
]",
);
assert_eq!(tmp, val);
//
Ok(())
}