surrealdb_expr/val/value/
rid.rs1use crate::expr::paths::ID;
2use crate::val::Value;
3
4impl Value {
5 pub fn rid(&self) -> Value {
6 self.pick(&ID)
7 }
8}
9
10#[cfg(test)]
11mod tests {
12
13 use surrealdb_strand::Strand;
14
15 use super::*;
16 use crate::syn;
17 use crate::val::{RecordId, RecordIdKey};
18
19 macro_rules! parse_val {
20 ($input:expr) => {
21 crate::val::convert_public_value_to_internal(syn::value($input).unwrap())
22 };
23 }
24
25 #[tokio::test]
26 async fn rid_none() {
27 let val = parse_val!("{ test: { other: null, something: 123 } }");
28 let res = Value::None;
29 assert_eq!(res, val.rid());
30 }
31
32 #[tokio::test]
33 async fn rid_some() {
34 let val = parse_val!("{ id: test:id, test: { other: null, something: 123 } }");
35 let res = Value::RecordId(RecordId {
36 table: "test".into(),
37 key: RecordIdKey::String(Strand::new_static("id")),
38 });
39 assert_eq!(res, val.rid());
40 }
41}