surrealpatch/lib/src/sql/value/clear.rs
Tobie Morgan Hitchcock 1017e2fffb Don’t clone variables when processing sub-contexts
Closes SUR-53

When creating a new context for subqueries or statement clauses, we used to have to clone any variables/values, and freeze the context, so that it could be used across threads and async boundaries.

Now with the new executor pattern for parallel queries, we can pass references instead, improving performance by removing unnecessary cloning of values.
2022-05-14 13:38:17 +01:00

43 lines
930 B
Rust

use crate::ctx::Context;
use crate::dbs::Options;
use crate::dbs::Transaction;
use crate::err::Error;
use crate::sql::value::Value;
impl Value {
pub async fn clear(
&mut self,
_ctx: &Context<'_>,
_opt: &Options,
_txn: &Transaction,
) -> Result<(), Error> {
*self = Value::base();
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::dbs::test::mock;
use crate::sql::test::Parse;
#[tokio::test]
async fn clear_none() {
let (ctx, opt, txn) = mock().await;
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{}");
val.clear(&ctx, &opt, &txn).await.unwrap();
assert_eq!(res, val);
}
#[tokio::test]
async fn clear_path() {
let (ctx, opt, txn) = mock().await;
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
let res = Value::parse("{}");
val.clear(&ctx, &opt, &txn).await.unwrap();
assert_eq!(res, val);
}
}