2022-01-20 23:00:57 +00:00
|
|
|
use crate::dbs::Executor;
|
|
|
|
use crate::dbs::Options;
|
|
|
|
use crate::dbs::Runtime;
|
|
|
|
use crate::err::Error;
|
|
|
|
use crate::sql::object::Object;
|
|
|
|
use crate::sql::value::Value;
|
|
|
|
|
|
|
|
impl Value {
|
|
|
|
pub async fn replace(
|
|
|
|
&mut self,
|
|
|
|
_ctx: &Runtime,
|
2022-02-06 21:06:52 +00:00
|
|
|
_opt: &Options,
|
2022-01-25 21:30:32 +00:00
|
|
|
_exe: &Executor<'_>,
|
2022-01-20 23:00:57 +00:00
|
|
|
val: &Object,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
// Clear all entries
|
|
|
|
*self = Value::from(val.clone());
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use crate::dbs::test::mock;
|
|
|
|
use crate::sql::test::Parse;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn replace() {
|
2022-01-29 16:15:30 +00:00
|
|
|
let (ctx, opt, exe) = mock();
|
2022-01-20 23:00:57 +00:00
|
|
|
let mut val = Value::parse("{ test: { other: null, something: 123 } }");
|
|
|
|
let res = Value::parse("{ other: true }");
|
|
|
|
let obj = Object::from(map! {String::from("other") => Value::from(true) });
|
2022-01-29 16:15:30 +00:00
|
|
|
val.replace(&ctx, &opt, &exe, &obj).await.unwrap();
|
2022-01-20 23:00:57 +00:00
|
|
|
assert_eq!(res, val);
|
|
|
|
}
|
|
|
|
}
|