2022-05-14 12:35:08 +00:00
|
|
|
use crate::ctx::Context;
|
2022-01-20 23:00:57 +00:00
|
|
|
use crate::dbs::Options;
|
2022-02-15 01:00:30 +00:00
|
|
|
use crate::dbs::Transaction;
|
2022-01-20 23:00:57 +00:00
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
pub async fn clear(
|
|
|
|
&mut self,
|
2022-05-14 12:35:08 +00:00
|
|
|
_ctx: &Context<'_>,
|
2022-02-06 21:06:52 +00:00
|
|
|
_opt: &Options,
|
2022-02-15 03:33:16 +00:00
|
|
|
_txn: &Transaction,
|
2022-01-20 23:00:57 +00:00
|
|
|
) -> Result<(), Error> {
|
2022-02-09 08:23:14 +00:00
|
|
|
*self = Value::base();
|
2022-01-20 23:00:57 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use crate::dbs::test::mock;
|
|
|
|
use crate::sql::test::Parse;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn clear_none() {
|
2022-02-15 01:00:30 +00:00
|
|
|
let (ctx, opt, txn) = mock().await;
|
2022-01-20 23:00:57 +00:00
|
|
|
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
|
|
|
|
let res = Value::parse("{}");
|
2022-02-15 01:00:30 +00:00
|
|
|
val.clear(&ctx, &opt, &txn).await.unwrap();
|
2022-01-20 23:00:57 +00:00
|
|
|
assert_eq!(res, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn clear_path() {
|
2022-02-15 01:00:30 +00:00
|
|
|
let (ctx, opt, txn) = mock().await;
|
2022-01-20 23:00:57 +00:00
|
|
|
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
|
|
|
|
let res = Value::parse("{}");
|
2022-02-15 01:00:30 +00:00
|
|
|
val.clear(&ctx, &opt, &txn).await.unwrap();
|
2022-01-20 23:00:57 +00:00
|
|
|
assert_eq!(res, val);
|
|
|
|
}
|
|
|
|
}
|