surrealpatch/lib/src/sql/value/object.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

use crate::dbs::Options;
use crate::dbs::Runtime;
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 {
2022-01-14 08:12:56 +00:00
pub async fn object(
&mut self,
ctx: &Runtime,
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);
}
}