use crate::ctx::Context; use crate::dbs::Options; use crate::dbs::Transaction; use crate::err::Error; use crate::sql::object::Object; use crate::sql::part::Part; use crate::sql::value::Value; impl Value { pub async fn object( &mut self, ctx: &Context<'_>, opt: &Options, txn: &Transaction, path: &[Part], ) -> Result<(), Error> { let val = Value::from(Object::default()); self.set(ctx, opt, txn, path, val).await } } #[cfg(test)] mod tests { use super::*; use crate::dbs::test::mock; use crate::sql::idiom::Idiom; use crate::sql::test::Parse; #[tokio::test] async fn object_none() { let (ctx, opt, txn) = mock().await; let idi = Idiom::default(); let mut val = Value::parse("{ test: { other: null, something: 123 } }"); let res = Value::parse("{}"); val.object(&ctx, &opt, &txn, &idi).await.unwrap(); assert_eq!(res, val); } #[tokio::test] async fn object_path() { let (ctx, opt, txn) = mock().await; let idi = Idiom::parse("test"); let mut val = Value::parse("{ test: { other: null, something: 123 } }"); let res = Value::parse("{ test: {} }"); val.object(&ctx, &opt, &txn, &idi).await.unwrap(); assert_eq!(res, val); } }