surrealdb/key/index/
bd.rs1use crate::idx::trees::store::NodeId;
3use crate::key::error::KeyCategory;
4use crate::key::key_req::KeyRequirements;
5use derive::Key;
6use serde::{Deserialize, Serialize};
7
8#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
9pub struct Bd<'a> {
10 __: u8,
11 _a: u8,
12 pub ns: &'a str,
13 _b: u8,
14 pub db: &'a str,
15 _c: u8,
16 pub tb: &'a str,
17 _d: u8,
18 pub ix: &'a str,
19 _e: u8,
20 _f: u8,
21 _g: u8,
22 pub node_id: Option<NodeId>,
23}
24
25impl KeyRequirements for Bd<'_> {
26 fn key_category(&self) -> KeyCategory {
27 KeyCategory::IndexBTreeNode
28 }
29}
30
31impl<'a> Bd<'a> {
32 pub fn new(
33 ns: &'a str,
34 db: &'a str,
35 tb: &'a str,
36 ix: &'a str,
37 node_id: Option<NodeId>,
38 ) -> Self {
39 Self {
40 __: b'/',
41 _a: b'*',
42 ns,
43 _b: b'*',
44 db,
45 _c: b'*',
46 tb,
47 _d: b'+',
48 ix,
49 _e: b'!',
50 _f: b'b',
51 _g: b'd',
52 node_id,
53 }
54 }
55}
56
57#[cfg(test)]
58mod tests {
59 #[test]
60 fn key() {
61 use super::*;
62 #[rustfmt::skip]
63 let val = Bd::new(
64 "testns",
65 "testdb",
66 "testtb",
67 "testix",
68 Some(7)
69 );
70 let enc = Bd::encode(&val).unwrap();
71 assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bd\x01\0\0\0\0\0\0\0\x07");
72 let dec = Bd::decode(&enc).unwrap();
73 assert_eq!(val, dec);
74 }
75}