surrealdb_core/sql/value/
rid.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::sql::paths::ID;
use crate::sql::value::Value;

impl Value {
	pub fn rid(&self) -> Value {
		self.pick(&*ID)
	}
}

#[cfg(test)]
mod tests {

	use super::*;
	use crate::sql::id::Id;
	use crate::sql::thing::Thing;
	use crate::syn::Parse;

	#[tokio::test]
	async fn rid_none() {
		let val = Value::parse("{ test: { other: null, something: 123 } }");
		let res = Value::None;
		assert_eq!(res, val.rid());
	}

	#[tokio::test]
	async fn rid_some() {
		let val = Value::parse("{ id: test:id, test: { other: null, something: 123 } }");
		let res = Value::Thing(Thing {
			tb: String::from("test"),
			id: Id::from("id"),
		});
		assert_eq!(res, val.rid());
	}
}