Sur 253 Change Cl->Nd, rework key/mod (#2257)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
76519b9c31
commit
769ed5ab85
78 changed files with 1265 additions and 1618 deletions
|
@ -26,7 +26,7 @@ pub(crate) use self::statement::*;
|
||||||
pub(crate) use self::transaction::*;
|
pub(crate) use self::transaction::*;
|
||||||
pub(crate) use self::variables::*;
|
pub(crate) use self::variables::*;
|
||||||
|
|
||||||
pub mod cl;
|
pub mod node;
|
||||||
|
|
||||||
mod processor;
|
mod processor;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -236,8 +236,8 @@ impl<'a> Processor<'a> {
|
||||||
nxt = Some(k.clone());
|
nxt = Some(k.clone());
|
||||||
}
|
}
|
||||||
// Parse the data from the store
|
// Parse the data from the store
|
||||||
let key: crate::key::thing::Thing = (&k).into();
|
let key: thing::Thing = (&k).into();
|
||||||
let val: crate::sql::value::Value = (&v).into();
|
let val: Value = (&v).into();
|
||||||
let rid = Thing::from((key.tb, key.id));
|
let rid = Thing::from((key.tb, key.id));
|
||||||
// Create a new operable value
|
// Create a new operable value
|
||||||
let val = Operable::Value(val);
|
let val = Operable::Value(val);
|
||||||
|
@ -319,8 +319,8 @@ impl<'a> Processor<'a> {
|
||||||
nxt = Some(k.clone());
|
nxt = Some(k.clone());
|
||||||
}
|
}
|
||||||
// Parse the data from the store
|
// Parse the data from the store
|
||||||
let key: crate::key::thing::Thing = (&k).into();
|
let key: thing::Thing = (&k).into();
|
||||||
let val: crate::sql::value::Value = (&v).into();
|
let val: Value = (&v).into();
|
||||||
let rid = Thing::from((key.tb, key.id));
|
let rid = Thing::from((key.tb, key.id));
|
||||||
// Create a new operable value
|
// Create a new operable value
|
||||||
let val = Operable::Value(val);
|
let val = Operable::Value(val);
|
||||||
|
@ -454,7 +454,7 @@ impl<'a> Processor<'a> {
|
||||||
nxt = Some(k.clone());
|
nxt = Some(k.clone());
|
||||||
}
|
}
|
||||||
// Parse the data from the store
|
// Parse the data from the store
|
||||||
let gra: crate::key::graph::Graph = (&k).into();
|
let gra: graph::Graph = (&k).into();
|
||||||
// Fetch the data from the store
|
// Fetch the data from the store
|
||||||
let key = thing::new(opt.ns(), opt.db(), gra.ft, &gra.fk);
|
let key = thing::new(opt.ns(), opt.db(), gra.ft, &gra.fk);
|
||||||
let val = txn.lock().await.get(key).await?;
|
let val = txn.lock().await.get(key).await?;
|
||||||
|
|
|
@ -256,7 +256,7 @@ pub enum Error {
|
||||||
|
|
||||||
// The cluster node does not exist
|
// The cluster node does not exist
|
||||||
#[error("The node '{value}' does not exist")]
|
#[error("The node '{value}' does not exist")]
|
||||||
ClNotFound {
|
NdNotFound {
|
||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,17 @@ use crate::err::Error;
|
||||||
use crate::idx::btree::NodeId;
|
use crate::idx::btree::NodeId;
|
||||||
use crate::idx::ft::docids::DocId;
|
use crate::idx::ft::docids::DocId;
|
||||||
use crate::idx::ft::terms::TermId;
|
use crate::idx::ft::terms::TermId;
|
||||||
use crate::key::bc::Bc;
|
use crate::key::index::bc::Bc;
|
||||||
use crate::key::bd::Bd;
|
use crate::key::index::bd::Bd;
|
||||||
use crate::key::bf::Bf;
|
use crate::key::index::bf::Bf;
|
||||||
use crate::key::bi::Bi;
|
use crate::key::index::bi::Bi;
|
||||||
use crate::key::bk::Bk;
|
use crate::key::index::bk::Bk;
|
||||||
use crate::key::bl::Bl;
|
use crate::key::index::bl::Bl;
|
||||||
use crate::key::bo::Bo;
|
use crate::key::index::bo::Bo;
|
||||||
use crate::key::bp::Bp;
|
use crate::key::index::bp::Bp;
|
||||||
use crate::key::bs::Bs;
|
use crate::key::index::bs::Bs;
|
||||||
use crate::key::bt::Bt;
|
use crate::key::index::bt::Bt;
|
||||||
use crate::key::bu::Bu;
|
use crate::key::index::bu::Bu;
|
||||||
use crate::kvs::{Key, Val};
|
use crate::kvs::{Key, Val};
|
||||||
use crate::sql::statements::DefineIndexStatement;
|
use crate::sql::statements::DefineIndexStatement;
|
||||||
use roaring::RoaringTreemap;
|
use roaring::RoaringTreemap;
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
use crate::idx::ft::terms::TermId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bc<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub term_id: TermId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bc<'a> {
|
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, term_id: TermId) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'c',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
term_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'c',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bc::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
7
|
|
||||||
);
|
|
||||||
let enc = Bc::encode(&val).unwrap();
|
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bctestix\0*\0\0\0\0\0\0\0\x07");
|
|
||||||
|
|
||||||
let dec = Bc::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
use crate::idx::btree::NodeId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bd<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub node_id: Option<NodeId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bd<'a> {
|
|
||||||
pub fn new(
|
|
||||||
ns: &'a str,
|
|
||||||
db: &'a str,
|
|
||||||
tb: &'a str,
|
|
||||||
ix: &'a str,
|
|
||||||
node_id: Option<NodeId>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'd',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
node_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'd',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bd::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
Some(7)
|
|
||||||
);
|
|
||||||
let enc = Bd::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bdtestix\0*\
|
|
||||||
\x01\
|
|
||||||
\0\0\0\0\0\0\0\x07"
|
|
||||||
);
|
|
||||||
let dec = Bd::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,122 +0,0 @@
|
||||||
use crate::idx::ft::docids::DocId;
|
|
||||||
use crate::idx::ft::terms::TermId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bf<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub term_id: TermId,
|
|
||||||
pub doc_id: DocId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bf<'a> {
|
|
||||||
pub fn new(
|
|
||||||
ns: &'a str,
|
|
||||||
db: &'a str,
|
|
||||||
tb: &'a str,
|
|
||||||
ix: &'a str,
|
|
||||||
term_id: TermId,
|
|
||||||
doc_id: DocId,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'f',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
term_id,
|
|
||||||
doc_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'f',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::key::bf::Bf;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bf::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
7,
|
|
||||||
13
|
|
||||||
);
|
|
||||||
let enc = Bf::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bftestix\0*\
|
|
||||||
\0\0\0\0\0\0\0\x07\
|
|
||||||
\0\0\0\0\0\0\0\x0d"
|
|
||||||
);
|
|
||||||
|
|
||||||
let dec = Bf::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
use crate::idx::btree::NodeId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bi<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub node_id: NodeId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bi<'a> {
|
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, node_id: NodeId) -> Self {
|
|
||||||
Bi {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'i',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
node_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'i',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bi::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
7
|
|
||||||
);
|
|
||||||
let enc = Bi::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bitestix\0*\
|
|
||||||
\0\0\0\0\0\0\0\x07"
|
|
||||||
);
|
|
||||||
|
|
||||||
let dec = Bi::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
use crate::idx::ft::docids::DocId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bk<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub doc_id: DocId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bk<'a> {
|
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, doc_id: DocId) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'k',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
doc_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'k',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bk::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
7
|
|
||||||
);
|
|
||||||
let enc = Bk::encode(&val).unwrap();
|
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!bktestix\0*\0\0\0\0\0\0\0\x07");
|
|
||||||
|
|
||||||
let dec = Bk::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
use crate::idx::btree::NodeId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bl<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub node_id: Option<NodeId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bl<'a> {
|
|
||||||
pub fn new(
|
|
||||||
ns: &'a str,
|
|
||||||
db: &'a str,
|
|
||||||
tb: &'a str,
|
|
||||||
ix: &'a str,
|
|
||||||
node_id: Option<NodeId>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'l',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
node_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'l',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bl::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
Some(7)
|
|
||||||
);
|
|
||||||
let enc = Bl::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bltestix\0*\
|
|
||||||
\x01\
|
|
||||||
\0\0\0\0\0\0\0\x07"
|
|
||||||
);
|
|
||||||
|
|
||||||
let dec = Bl::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
use crate::idx::btree::NodeId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bp<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub node_id: Option<NodeId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bp<'a> {
|
|
||||||
pub fn new(
|
|
||||||
ns: &'a str,
|
|
||||||
db: &'a str,
|
|
||||||
tb: &'a str,
|
|
||||||
ix: &'a str,
|
|
||||||
node_id: Option<NodeId>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'p',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
node_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'p',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bp::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
Some(7)
|
|
||||||
);
|
|
||||||
let enc = Bp::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bptestix\0*\
|
|
||||||
\x01\
|
|
||||||
\0\0\0\0\0\0\0\x07"
|
|
||||||
);
|
|
||||||
|
|
||||||
let dec = Bp::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
use crate::idx::btree::NodeId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bt<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub node_id: Option<NodeId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bt<'a> {
|
|
||||||
pub fn new(
|
|
||||||
ns: &'a str,
|
|
||||||
db: &'a str,
|
|
||||||
tb: &'a str,
|
|
||||||
ix: &'a str,
|
|
||||||
node_id: Option<NodeId>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b't',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
node_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b't',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bt::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
Some(7)
|
|
||||||
);
|
|
||||||
let enc = Bt::encode(&val).unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
enc,
|
|
||||||
b"/*testns\0*testdb\0*testtb\0!bttestix\0*\
|
|
||||||
\x01\
|
|
||||||
\0\0\0\0\0\0\0\x07"
|
|
||||||
);
|
|
||||||
let dec = Bt::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
use crate::idx::ft::terms::TermId;
|
|
||||||
use derive::Key;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Bu<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
pub term_id: TermId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Bu<'a> {
|
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, term_id: TermId) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'u',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
term_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'u',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn key() {
|
|
||||||
use super::*;
|
|
||||||
#[rustfmt::skip]
|
|
||||||
let val = Bu::new(
|
|
||||||
"testns",
|
|
||||||
"testdb",
|
|
||||||
"testtb",
|
|
||||||
"testix",
|
|
||||||
7
|
|
||||||
);
|
|
||||||
let enc = Bu::encode(&val).unwrap();
|
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0!butestix\0*\0\0\0\0\0\0\0\x07");
|
|
||||||
|
|
||||||
let dec = Bu::decode(&enc).unwrap();
|
|
||||||
assert_eq!(val, dec);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores change feeds
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -30,8 +31,8 @@ pub fn new<'a>(ns: &'a str, db: &'a str, ts: u64, tb: &'a str) -> Cf<'a> {
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn versionstamped_key_prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn versionstamped_key_prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = crate::key::database::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'f']);
|
k.extend_from_slice(&[b'#']);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +50,8 @@ pub fn versionstamped_key_suffix(tb: &str) -> Vec<u8> {
|
||||||
/// specified versionstamp.
|
/// specified versionstamp.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn ts_prefix(ns: &str, db: &str, vs: vs::Versionstamp) -> Vec<u8> {
|
pub fn ts_prefix(ns: &str, db: &str, vs: vs::Versionstamp) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = crate::key::database::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'f']);
|
k.extend_from_slice(&[b'#']);
|
||||||
k.extend_from_slice(&vs);
|
k.extend_from_slice(&vs);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
@ -58,16 +59,16 @@ pub fn ts_prefix(ns: &str, db: &str, vs: vs::Versionstamp) -> Vec<u8> {
|
||||||
/// Returns the prefix for the whole database change feeds
|
/// Returns the prefix for the whole database change feeds
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = crate::key::database::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'f', 0x00]);
|
k.extend_from_slice(&[b'#', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the suffix for the whole database change feeds
|
/// Returns the suffix for the whole database change feeds
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = crate::key::database::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'f', 0xff]);
|
k.extend_from_slice(&[b'#', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
//! Stores the key prefix for all keys under a database
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Database<'a> {
|
pub struct All<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -10,11 +11,11 @@ pub struct Database<'a> {
|
||||||
pub db: &'a str,
|
pub db: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str) -> Database<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str) -> All<'a> {
|
||||||
Database::new(ns, db)
|
All::new(ns, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Database<'a> {
|
impl<'a> All<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str) -> Self {
|
pub fn new(ns: &'a str, db: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/', // /
|
__: b'/', // /
|
||||||
|
@ -32,14 +33,14 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Database::new(
|
let val = All::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testdb",
|
"testdb",
|
||||||
);
|
);
|
||||||
let enc = Database::encode(&val).unwrap();
|
let enc = All::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0");
|
assert_eq!(enc, b"/*testns\0*testdb\0");
|
||||||
|
|
||||||
let dec = Database::decode(&enc).unwrap();
|
let dec = All::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a DEFINE ANALYZER config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Az<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'a', b'z', 0x00]);
|
k.extend_from_slice(&[b'!', b'a', b'z', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'a', b'z', 0xff]);
|
k.extend_from_slice(&[b'!', b'a', b'z', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE FUNCTION config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, fc: &'a str) -> Fc<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b'n', 0x00]);
|
k.extend_from_slice(&[b'!', b'f', b'n', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b'n', 0xff]);
|
k.extend_from_slice(&[b'!', b'f', b'n', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
|
//! Stores a DEFINE LOGIN ON DATABASE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Dl<'a> {
|
pub struct Lg<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -14,23 +15,23 @@ pub struct Dl<'a> {
|
||||||
pub dl: &'a str,
|
pub dl: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str, dl: &'a str) -> Dl<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str, dl: &'a str) -> Lg<'a> {
|
||||||
Dl::new(ns, db, dl)
|
Lg::new(ns, db, dl)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b'l', 0x00]);
|
k.extend_from_slice(&[b'!', b'l', b'g', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b'l', 0xff]);
|
k.extend_from_slice(&[b'!', b'l', b'g', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Dl<'a> {
|
impl<'a> Lg<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str, dl: &'a str) -> Self {
|
pub fn new(ns: &'a str, db: &'a str, dl: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
|
@ -39,8 +40,8 @@ impl<'a> Dl<'a> {
|
||||||
_b: b'*',
|
_b: b'*',
|
||||||
db,
|
db,
|
||||||
_c: b'!',
|
_c: b'!',
|
||||||
_d: b'd',
|
_d: b'l',
|
||||||
_e: b'l',
|
_e: b'g',
|
||||||
dl,
|
dl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,15 +53,15 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Dl::new(
|
let val = Lg::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testdb",
|
"testdb",
|
||||||
"testdl",
|
"testdl",
|
||||||
);
|
);
|
||||||
let enc = Dl::encode(&val).unwrap();
|
let enc = Lg::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0!dltestdl\0");
|
assert_eq!(enc, b"/*testns\0*testdb\0!lgtestdl\0");
|
||||||
|
|
||||||
let dec = Dl::decode(&enc).unwrap();
|
let dec = Lg::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
9
lib/src/key/database/mod.rs
Normal file
9
lib/src/key/database/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod az;
|
||||||
|
pub mod fc;
|
||||||
|
pub mod lg;
|
||||||
|
pub mod pa;
|
||||||
|
pub mod sc;
|
||||||
|
pub mod tb;
|
||||||
|
pub mod tk;
|
||||||
|
pub mod vs;
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a DEFINE PARAM config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, pa: &'a str) -> Pa<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'p', b'a', 0x00]);
|
k.extend_from_slice(&[b'!', b'p', b'a', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'p', b'a', 0xff]);
|
k.extend_from_slice(&[b'!', b'p', b'a', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a DEFINE SCOPE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str) -> Sc<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b's', b'c', 0x00]);
|
k.extend_from_slice(&[b'!', b's', b'c', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b's', b'c', 0xff]);
|
k.extend_from_slice(&[b'!', b's', b'c', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a DEFINE TABLE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Tb<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b't', b'b', 0x00]);
|
k.extend_from_slice(&[b'!', b't', b'b', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b't', b'b', 0xff]);
|
k.extend_from_slice(&[b'!', b't', b'b', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
|
/// Stores a DEFINE LOGIN ON DATABASE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Dt<'a> {
|
pub struct Tk<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -14,23 +15,23 @@ pub struct Dt<'a> {
|
||||||
pub tk: &'a str,
|
pub tk: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Dt<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Tk<'a> {
|
||||||
Dt::new(ns, db, tb)
|
Tk::new(ns, db, tb)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b't', 0x00]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
|
||||||
let mut k = super::database::new(ns, db).encode().unwrap();
|
let mut k = super::all::new(ns, db).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b't', 0xff]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Dt<'a> {
|
impl<'a> Tk<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str, tk: &'a str) -> Self {
|
pub fn new(ns: &'a str, db: &'a str, tk: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
|
@ -39,8 +40,8 @@ impl<'a> Dt<'a> {
|
||||||
_b: b'*',
|
_b: b'*',
|
||||||
db,
|
db,
|
||||||
_c: b'!',
|
_c: b'!',
|
||||||
_d: b'd',
|
_d: b't',
|
||||||
_e: b't',
|
_e: b'k',
|
||||||
tk,
|
tk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,27 +53,27 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Dt::new(
|
let val = Tk::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testdb",
|
"testdb",
|
||||||
"testtk",
|
"testtk",
|
||||||
);
|
);
|
||||||
let enc = Dt::encode(&val).unwrap();
|
let enc = Tk::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\x00*testdb\x00!dttesttk\x00");
|
assert_eq!(enc, b"/*testns\x00*testdb\x00!tktesttk\x00");
|
||||||
|
|
||||||
let dec = Dt::decode(&enc).unwrap();
|
let dec = Tk::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prefix() {
|
fn test_prefix() {
|
||||||
let val = super::prefix("testns", "testdb");
|
let val = super::prefix("testns", "testdb");
|
||||||
assert_eq!(val, b"/*testns\0*testdb\0!dt\0");
|
assert_eq!(val, b"/*testns\0*testdb\0!tk\0");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_suffix() {
|
fn test_suffix() {
|
||||||
let val = super::suffix("testns", "testdb");
|
let val = super::suffix("testns", "testdb");
|
||||||
assert_eq!(val, b"/*testns\0*testdb\0!dt\xff");
|
assert_eq!(val, b"/*testns\0*testdb\0!tk\xff");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
|
//! Stores database versionstamps
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// Dv stands for Database Versionstamp
|
// Vs stands for Database Versionstamp
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Dv<'a> {
|
pub struct Vs<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -15,21 +16,21 @@ pub struct Dv<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str) -> Dv<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str) -> Vs<'a> {
|
||||||
Dv::new(ns, db)
|
Vs::new(ns, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Dv<'a> {
|
impl<'a> Vs<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str) -> Self {
|
pub fn new(ns: &'a str, db: &'a str) -> Self {
|
||||||
Dv {
|
Vs {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
_a: b'*',
|
_a: b'*',
|
||||||
ns,
|
ns,
|
||||||
_b: b'*',
|
_b: b'*',
|
||||||
db,
|
db,
|
||||||
_d: b'!',
|
_d: b'!',
|
||||||
_e: b't',
|
_e: b'v',
|
||||||
_f: b't',
|
_f: b's',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,12 +41,12 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Dv::new(
|
let val = Vs::new(
|
||||||
"test",
|
"test",
|
||||||
"test",
|
"test",
|
||||||
);
|
);
|
||||||
let enc = Dv::encode(&val).unwrap();
|
let enc = Vs::encode(&val).unwrap();
|
||||||
let dec = Dv::decode(&enc).unwrap();
|
let dec = Vs::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Debug purposes only. It may be used in logs. Not for key handling in implementation code.
|
||||||
use crate::kvs::Key;
|
use crate::kvs::Key;
|
||||||
|
|
||||||
/// Helpers for debugging keys
|
/// Helpers for debugging keys
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a graph edge pointer
|
||||||
use crate::sql::dir::Dir;
|
use crate::sql::dir::Dir;
|
||||||
use crate::sql::id::Id;
|
use crate::sql::id::Id;
|
||||||
use crate::sql::thing::Thing;
|
use crate::sql::thing::Thing;
|
56
lib/src/key/index/all.rs
Normal file
56
lib/src/key/index/all.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//! Stores the key prefix for all keys under an index
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct All<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> All<'a> {
|
||||||
|
All::new(ns, db, tb, ix)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> All<'a> {
|
||||||
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = All::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
);
|
||||||
|
let enc = All::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0");
|
||||||
|
|
||||||
|
let dec = All::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
63
lib/src/key/index/bc.rs
Normal file
63
lib/src/key/index/bc.rs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
//! Stores Doc list for each term
|
||||||
|
use crate::idx::ft::terms::TermId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bc<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub term_id: TermId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bc<'a> {
|
||||||
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, term_id: TermId) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'c',
|
||||||
|
term_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bc::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
7
|
||||||
|
);
|
||||||
|
let enc = Bc::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bc\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bc::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
67
lib/src/key/index/bd.rs
Normal file
67
lib/src/key/index/bd.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
//! Stores BTree nodes for doc ids
|
||||||
|
use crate::idx::btree::NodeId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bd<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub node_id: Option<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bd<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ns: &'a str,
|
||||||
|
db: &'a str,
|
||||||
|
tb: &'a str,
|
||||||
|
ix: &'a str,
|
||||||
|
node_id: Option<NodeId>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'd',
|
||||||
|
node_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bd::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
Some(7)
|
||||||
|
);
|
||||||
|
let enc = Bd::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bd\x01\0\0\0\0\0\0\0\x07");
|
||||||
|
let dec = Bd::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
77
lib/src/key/index/bf.rs
Normal file
77
lib/src/key/index/bf.rs
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
//! Stores Term/Doc frequency
|
||||||
|
use crate::idx::ft::docids::DocId;
|
||||||
|
use crate::idx::ft::terms::TermId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bf<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub term_id: TermId,
|
||||||
|
pub doc_id: DocId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bf<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ns: &'a str,
|
||||||
|
db: &'a str,
|
||||||
|
tb: &'a str,
|
||||||
|
ix: &'a str,
|
||||||
|
term_id: TermId,
|
||||||
|
doc_id: DocId,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'f',
|
||||||
|
term_id,
|
||||||
|
doc_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::key::index::bf::Bf;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bf::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
7,
|
||||||
|
13
|
||||||
|
);
|
||||||
|
let enc = Bf::encode(&val).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
enc,
|
||||||
|
b"/*testns\0*testdb\0*testtb\0+testix\0!bf\0\0\0\0\0\0\0\x07\0\0\0\0\0\0\0\x0d"
|
||||||
|
);
|
||||||
|
|
||||||
|
let dec = Bf::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
62
lib/src/key/index/bi.rs
Normal file
62
lib/src/key/index/bi.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//! Stores doc keys for doc_ids
|
||||||
|
use crate::idx::btree::NodeId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bi<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub node_id: NodeId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bi<'a> {
|
||||||
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, node_id: NodeId) -> Self {
|
||||||
|
Bi {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'i',
|
||||||
|
node_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bi::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
7
|
||||||
|
);
|
||||||
|
let enc = Bi::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bi\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bi::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
62
lib/src/key/index/bk.rs
Normal file
62
lib/src/key/index/bk.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//! Stores the term list for doc_ids
|
||||||
|
use crate::idx::ft::docids::DocId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bk<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub doc_id: DocId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bk<'a> {
|
||||||
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, doc_id: DocId) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'k',
|
||||||
|
doc_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bk::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
7
|
||||||
|
);
|
||||||
|
let enc = Bk::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bk\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bk::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
68
lib/src/key/index/bl.rs
Normal file
68
lib/src/key/index/bl.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//! Stores BTree nodes for doc lengths
|
||||||
|
use crate::idx::btree::NodeId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bl<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub node_id: Option<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bl<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ns: &'a str,
|
||||||
|
db: &'a str,
|
||||||
|
tb: &'a str,
|
||||||
|
ix: &'a str,
|
||||||
|
node_id: Option<NodeId>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'l',
|
||||||
|
node_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bl::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
Some(7)
|
||||||
|
);
|
||||||
|
let enc = Bl::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bl\x01\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bl::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
|
//! Stores the offsets
|
||||||
use crate::idx::ft::docids::DocId;
|
use crate::idx::ft::docids::DocId;
|
||||||
use crate::idx::ft::terms::TermId;
|
use crate::idx::ft::terms::TermId;
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::ops::Range;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Bo<'a> {
|
pub struct Bo<'a> {
|
||||||
|
@ -14,9 +14,9 @@ pub struct Bo<'a> {
|
||||||
_c: u8,
|
_c: u8,
|
||||||
pub tb: &'a str,
|
pub tb: &'a str,
|
||||||
_d: u8,
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
_e: u8,
|
_e: u8,
|
||||||
_f: u8,
|
_f: u8,
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
_g: u8,
|
||||||
pub doc_id: DocId,
|
pub doc_id: DocId,
|
||||||
pub term_id: TermId,
|
pub term_id: TermId,
|
||||||
|
@ -39,58 +39,15 @@ impl<'a> Bo<'a> {
|
||||||
db,
|
db,
|
||||||
_c: b'*',
|
_c: b'*',
|
||||||
tb,
|
tb,
|
||||||
_d: b'!',
|
_d: b'+',
|
||||||
_e: b'b',
|
|
||||||
_f: b'o',
|
|
||||||
ix,
|
ix,
|
||||||
_g: b'*',
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'o',
|
||||||
doc_id,
|
doc_id,
|
||||||
term_id,
|
term_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn range(ns: &str, db: &str, tb: &str, ix: &str) -> Range<Vec<u8>> {
|
|
||||||
let mut beg = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
beg.extend_from_slice(&[0x00]);
|
|
||||||
let mut end = Prefix::new(ns, db, tb, ix).encode().unwrap();
|
|
||||||
end.extend_from_slice(&[0xff]);
|
|
||||||
beg..end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
|
||||||
pub struct Prefix<'a> {
|
|
||||||
__: u8,
|
|
||||||
_a: u8,
|
|
||||||
pub ns: &'a str,
|
|
||||||
_b: u8,
|
|
||||||
pub db: &'a str,
|
|
||||||
_c: u8,
|
|
||||||
pub tb: &'a str,
|
|
||||||
_d: u8,
|
|
||||||
_e: u8,
|
|
||||||
_f: u8,
|
|
||||||
pub ix: &'a str,
|
|
||||||
_g: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
|
||||||
fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
|
|
||||||
Self {
|
|
||||||
__: b'/',
|
|
||||||
_a: b'*',
|
|
||||||
ns,
|
|
||||||
_b: b'*',
|
|
||||||
db,
|
|
||||||
_c: b'*',
|
|
||||||
tb,
|
|
||||||
_d: b'!',
|
|
||||||
_e: b'b',
|
|
||||||
_f: b'o',
|
|
||||||
ix,
|
|
||||||
_g: b'*',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -109,7 +66,7 @@ mod tests {
|
||||||
let enc = Bo::encode(&val).unwrap();
|
let enc = Bo::encode(&val).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
enc,
|
enc,
|
||||||
b"/*testns\0*testdb\0*testtb\0!botestix\0*\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x02"
|
b"/*testns\0*testdb\0*testtb\0+testix\0!bo\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\x02"
|
||||||
);
|
);
|
||||||
|
|
||||||
let dec = Bo::decode(&enc).unwrap();
|
let dec = Bo::decode(&enc).unwrap();
|
68
lib/src/key/index/bp.rs
Normal file
68
lib/src/key/index/bp.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//! Stores BTree nodes for postings
|
||||||
|
use crate::idx::btree::NodeId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bp<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub node_id: Option<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bp<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ns: &'a str,
|
||||||
|
db: &'a str,
|
||||||
|
tb: &'a str,
|
||||||
|
ix: &'a str,
|
||||||
|
node_id: Option<NodeId>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'p',
|
||||||
|
node_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bp::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
Some(7)
|
||||||
|
);
|
||||||
|
let enc = Bp::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bp\x01\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bp::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores FullText index states
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
67
lib/src/key/index/bt.rs
Normal file
67
lib/src/key/index/bt.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
//! Stores BTree nodes for terms
|
||||||
|
use crate::idx::btree::NodeId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bt<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub node_id: Option<NodeId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bt<'a> {
|
||||||
|
pub fn new(
|
||||||
|
ns: &'a str,
|
||||||
|
db: &'a str,
|
||||||
|
tb: &'a str,
|
||||||
|
ix: &'a str,
|
||||||
|
node_id: Option<NodeId>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b't',
|
||||||
|
node_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bt::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
Some(7)
|
||||||
|
);
|
||||||
|
let enc = Bt::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bt\x01\0\0\0\0\0\0\0\x07");
|
||||||
|
let dec = Bt::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
62
lib/src/key/index/bu.rs
Normal file
62
lib/src/key/index/bu.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//! Stores terms for term_ids
|
||||||
|
use crate::idx::ft::terms::TermId;
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct Bu<'a> {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
pub ns: &'a str,
|
||||||
|
_b: u8,
|
||||||
|
pub db: &'a str,
|
||||||
|
_c: u8,
|
||||||
|
pub tb: &'a str,
|
||||||
|
_d: u8,
|
||||||
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
|
_f: u8,
|
||||||
|
_g: u8,
|
||||||
|
pub term_id: TermId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Bu<'a> {
|
||||||
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str, term_id: TermId) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'*',
|
||||||
|
ns,
|
||||||
|
_b: b'*',
|
||||||
|
db,
|
||||||
|
_c: b'*',
|
||||||
|
tb,
|
||||||
|
_d: b'+',
|
||||||
|
ix,
|
||||||
|
_e: b'!',
|
||||||
|
_f: b'b',
|
||||||
|
_g: b'u',
|
||||||
|
term_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = Bu::new(
|
||||||
|
"testns",
|
||||||
|
"testdb",
|
||||||
|
"testtb",
|
||||||
|
"testix",
|
||||||
|
7
|
||||||
|
);
|
||||||
|
let enc = Bu::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/*testns\0*testdb\0*testtb\0+testix\0!bu\0\0\0\0\0\0\0\x07");
|
||||||
|
|
||||||
|
let dec = Bu::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,17 @@
|
||||||
use crate::key::CHAR_INDEX;
|
//! Stores an index entry
|
||||||
|
pub mod all;
|
||||||
|
pub mod bc;
|
||||||
|
pub mod bd;
|
||||||
|
pub mod bf;
|
||||||
|
pub mod bi;
|
||||||
|
pub mod bk;
|
||||||
|
pub mod bl;
|
||||||
|
pub mod bo;
|
||||||
|
pub mod bp;
|
||||||
|
pub mod bs;
|
||||||
|
pub mod bt;
|
||||||
|
pub mod bu;
|
||||||
|
|
||||||
use crate::sql::array::Array;
|
use crate::sql::array::Array;
|
||||||
use crate::sql::id::Id;
|
use crate::sql::id::Id;
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
|
@ -16,6 +29,7 @@ struct Prefix<'a> {
|
||||||
pub tb: &'a str,
|
pub tb: &'a str,
|
||||||
_d: u8,
|
_d: u8,
|
||||||
pub ix: &'a str,
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Prefix<'a> {
|
impl<'a> Prefix<'a> {
|
||||||
|
@ -28,8 +42,9 @@ impl<'a> Prefix<'a> {
|
||||||
db,
|
db,
|
||||||
_c: b'*',
|
_c: b'*',
|
||||||
tb,
|
tb,
|
||||||
_d: CHAR_INDEX,
|
_d: b'+',
|
||||||
ix,
|
ix,
|
||||||
|
_e: b'*',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +60,7 @@ struct PrefixIds<'a> {
|
||||||
pub tb: &'a str,
|
pub tb: &'a str,
|
||||||
_d: u8,
|
_d: u8,
|
||||||
pub ix: &'a str,
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
pub fd: Array,
|
pub fd: Array,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +74,9 @@ impl<'a> PrefixIds<'a> {
|
||||||
db,
|
db,
|
||||||
_c: b'*',
|
_c: b'*',
|
||||||
tb,
|
tb,
|
||||||
_d: CHAR_INDEX,
|
_d: b'+',
|
||||||
ix,
|
ix,
|
||||||
|
_e: b'*',
|
||||||
fd: fd.to_owned(),
|
fd: fd.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +93,7 @@ pub struct Index<'a> {
|
||||||
pub tb: &'a str,
|
pub tb: &'a str,
|
||||||
_d: u8,
|
_d: u8,
|
||||||
pub ix: &'a str,
|
pub ix: &'a str,
|
||||||
|
_e: u8,
|
||||||
pub fd: Array,
|
pub fd: Array,
|
||||||
pub id: Option<Id>,
|
pub id: Option<Id>,
|
||||||
}
|
}
|
||||||
|
@ -97,8 +115,9 @@ impl<'a> Index<'a> {
|
||||||
db,
|
db,
|
||||||
_c: b'*',
|
_c: b'*',
|
||||||
tb,
|
tb,
|
||||||
_d: CHAR_INDEX,
|
_d: b'+',
|
||||||
ix,
|
ix,
|
||||||
|
_e: b'*',
|
||||||
fd,
|
fd,
|
||||||
id,
|
id,
|
||||||
}
|
}
|
||||||
|
@ -138,7 +157,7 @@ mod tests {
|
||||||
let enc = Index::encode(&val).unwrap();
|
let enc = Index::encode(&val).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
enc,
|
enc,
|
||||||
b"/*testns\0*testdb\0*testtb\0\xa4testix\0\0\0\0\x04testfd1\0\0\0\0\x04testfd2\0\x01\x01\0\0\0\x01testid\0"
|
b"/*testns\0*testdb\0*testtb\0+testix\0*\0\0\0\x04testfd1\0\0\0\0\x04testfd2\0\x01\x01\0\0\0\x01testid\0"
|
||||||
);
|
);
|
||||||
|
|
||||||
let dec = Index::decode(&enc).unwrap();
|
let dec = Index::decode(&enc).unwrap();
|
|
@ -1,98 +1,67 @@
|
||||||
//! How the keys are structured in the key value store
|
//! How the keys are structured in the key value store
|
||||||
///
|
///
|
||||||
/// KV /
|
/// crate::key::root::all /
|
||||||
|
/// crate::key::root::hb /!hb{ts}/{nd}
|
||||||
|
/// crate::key::root::nd /!nd{nd}
|
||||||
|
/// crate::key::root::ns /!ns{ns}
|
||||||
///
|
///
|
||||||
/// HB /!hb{ts}/{nd}
|
/// crate::key::node::all /${nd}
|
||||||
|
/// crate::key::node::lq /${nd}!lq{lq}{ns}{db}
|
||||||
///
|
///
|
||||||
/// ND /!nd{nd}
|
/// crate::key::namespace::all /*{ns}
|
||||||
/// NQ /!nd{nd}*{ns}*{db}!lq{lq}
|
/// crate::key::namespace::db /*{ns}!db{db}
|
||||||
|
/// crate::key::namespace::lg /*{ns}!lg{lg}
|
||||||
|
/// crate::key::namespace::tk /*{ns}!tk{tk}
|
||||||
///
|
///
|
||||||
/// NS /!ns{ns}
|
/// crate::key::database::all /*{ns}*{db}
|
||||||
|
/// crate::key::database::az /*{ns}*{db}!az{az}
|
||||||
|
/// crate::key::database::cf /*{ns}*{db}!cf{ts}
|
||||||
|
/// crate::key::database::fc /*{ns}*{db}!fn{fc}
|
||||||
|
/// crate::key::database::lg /*{ns}*{db}!lg{lg}
|
||||||
|
/// crate::key::database::pa /*{ns}*{db}!pa{pa}
|
||||||
|
/// crate::key::database::sc /*{ns}*{db}!sc{sc}
|
||||||
|
/// crate::key::database::tb /*{ns}*{db}!tb{tb}
|
||||||
|
/// crate::key::database::tk /*{ns}*{db}!tk{tk}
|
||||||
|
/// crate::key::database::vs /*{ns}*{db}!vs
|
||||||
///
|
///
|
||||||
/// Namespace /*{ns}
|
/// crate::key::scope::all /*{ns}*{db}±{sc}
|
||||||
/// NL /*{ns}!nl{us}
|
/// crate::key::scope::tk /*{ns}*{db}±{sc}!tk{tk}
|
||||||
/// NT /*{ns}!nt{tk}
|
|
||||||
/// DB /*{ns}!db{db}
|
|
||||||
///
|
///
|
||||||
/// Database /*{ns}*{db}
|
/// crate::key::table::all /*{ns}*{db}*{tb}
|
||||||
/// AZ /*{ns}*{db}!az{az}
|
/// crate::key::table::ev /*{ns}*{db}*{tb}!ev{ev}
|
||||||
/// CF /*{ns}*{db}!cf{ts}
|
/// crate::key::table::fd /*{ns}*{db}*{tb}!fd{fd}
|
||||||
/// DL /*{ns}*{db}!dl{us}
|
/// crate::key::table::ft /*{ns}*{db}*{tb}!ft{ft}
|
||||||
/// DT /*{ns}*{db}!dt{tk}
|
/// crate::key::table::ix /*{ns}*{db}*{tb}!ix{ix}
|
||||||
/// PA /*{ns}*{db}!pa{pa}
|
/// crate::key::table::lq /*{ns}*{db}*{tb}!lq{lq}
|
||||||
/// SC /*{ns}*{db}!sc{sc}
|
|
||||||
/// TB /*{ns}*{db}!tb{tb}
|
|
||||||
///
|
///
|
||||||
/// Scope /*{ns}*{db}±{sc}
|
/// crate::key::index::all /*{ns}*{db}*{tb}+{ix}
|
||||||
/// ST /*{ns}*{db}±{sc}!st{tk}
|
/// crate::key::index::bc /*{ns}*{db}*{tb}+{ix}!bc{id}
|
||||||
|
/// crate::key::index::bd /*{ns}*{db}*{tb}+{ix}!bd{id}
|
||||||
|
/// crate::key::index::bf /*{ns}*{db}*{tb}+{ix}!bf{id}
|
||||||
|
/// crate::key::index::bi /*{ns}*{db}*{tb}+{ix}!bi{id}
|
||||||
|
/// crate::key::index::bk /*{ns}*{db}*{tb}+{ix}!bk{id}
|
||||||
|
/// crate::key::index::bl /*{ns}*{db}*{tb}+{ix}!bl{id}
|
||||||
|
/// crate::key::index::bo /*{ns}*{db}*{tb}+{ix}!bo{id}
|
||||||
|
/// crate::key::index::bp /*{ns}*{db}*{tb}+{ix}!bp{id}
|
||||||
|
/// crate::key::index::bs /*{ns}*{db}*{tb}+{ix}!bs
|
||||||
|
/// crate::key::index::bt /*{ns}*{db}*{tb}+{ix}!bt{id}
|
||||||
|
/// crate::key::index::bu /*{ns}*{db}*{tb}+{ix}!bu{id}
|
||||||
|
/// crate::key::index /*{ns}*{db}*{tb}+{ix}*{fd}{id}
|
||||||
///
|
///
|
||||||
/// AZ /*{ns}*{db}!az{az}
|
/// crate::key::change /*{ns}*{db}#{ts}
|
||||||
///
|
///
|
||||||
/// Table /*{ns}*{db}*{tb}
|
/// crate::key::thing /*{ns}*{db}*{tb}*{id}
|
||||||
/// EV /*{ns}*{db}*{tb}!ev{ev}
|
|
||||||
/// FD /*{ns}*{db}*{tb}!fd{fd}
|
|
||||||
/// FT /*{ns}*{db}*{tb}!ft{ft}
|
|
||||||
/// IX /*{ns}*{db}*{tb}!ix{ix}
|
|
||||||
/// LV /*{ns}*{db}*{tb}!lv{lv}
|
|
||||||
///
|
///
|
||||||
/// Thing /*{ns}*{db}*{tb}*{id}
|
/// crate::key::graph /*{ns}*{db}*{tb}~{id}{eg}{fk}
|
||||||
///
|
///
|
||||||
/// Graph /*{ns}*{db}*{tb}~{id}{eg}{fk}
|
pub mod change;
|
||||||
///
|
pub mod database;
|
||||||
/// Index /*{ns}*{db}*{tb}¤{ix}{fd}{id}
|
pub mod debug;
|
||||||
///
|
pub mod graph;
|
||||||
/// BC /*{ns}*{db}*{tb}!bc{ix}*{id}
|
pub mod index;
|
||||||
/// BD /*{ns}*{db}*{tb}!bd{ix}*{id}
|
pub mod namespace;
|
||||||
/// BF /*{ns}*{db}*{tb}!bf{ix}*{id}
|
pub mod node;
|
||||||
/// BI /*{ns}*{db}*{tb}!bi{ix}*{id}
|
pub mod root;
|
||||||
/// BK /*{ns}*{db}*{tb}!bk{ix}*{id}
|
pub mod scope;
|
||||||
/// BL /*{ns}*{db}*{tb}!bl{ix}*{id}
|
pub mod table;
|
||||||
/// BP /*{ns}*{db}*{tb}!bp{ix}*{id}
|
pub mod thing;
|
||||||
/// BS /*{ns}*{db}*{tb}!bs{ix}
|
|
||||||
/// BT /*{ns}*{db}*{tb}!bt{ix}*{id}
|
|
||||||
/// BU /*{ns}*{db}*{tb}!bu{ix}*{id}
|
|
||||||
pub mod az; // Stores a DEFINE ANALYZER config definition
|
|
||||||
pub mod bc; // Stores Doc list for each term
|
|
||||||
pub mod bd; // Stores BTree nodes for doc ids
|
|
||||||
pub mod bf; // Stores Term/Doc frequency
|
|
||||||
pub mod bi; // Stores doc keys for doc_ids
|
|
||||||
pub mod bk; // Stores the term list for doc_ids
|
|
||||||
pub mod bl; // Stores BTree nodes for doc lengths
|
|
||||||
pub mod bo; // Stores the offsets
|
|
||||||
pub mod bp; // Stores BTree nodes for postings
|
|
||||||
pub mod bs; // Stores FullText index states
|
|
||||||
pub mod bt; // Stores BTree nodes for terms
|
|
||||||
pub mod bu; // Stores terms for term_ids
|
|
||||||
pub mod cf; // Stores change feeds
|
|
||||||
pub mod cl; // Stores cluster membership information
|
|
||||||
pub mod database; // Stores the key prefix for all keys under a database
|
|
||||||
pub mod db; // Stores a DEFINE DATABASE config definition
|
|
||||||
pub mod debug; // Debug purposes only. It may be used in logs. Not for key handling in implementation code.
|
|
||||||
pub mod dl; // Stores a DEFINE LOGIN ON DATABASE config definition
|
|
||||||
pub mod dt; // Stores a DEFINE LOGIN ON DATABASE config definition
|
|
||||||
pub mod dv; // Stores database versionstamps
|
|
||||||
pub mod ev; // Stores a DEFINE EVENT config definition
|
|
||||||
pub mod fc; // Stores a DEFINE FUNCTION config definition
|
|
||||||
pub mod fd; // Stores a DEFINE FIELD config definition
|
|
||||||
pub mod ft; // Stores a DEFINE TABLE AS config definition
|
|
||||||
pub mod graph; // Stores a graph edge pointer
|
|
||||||
pub mod hb; // Stores a heartbeat per registered cluster node
|
|
||||||
pub mod index; // Stores an index entry
|
|
||||||
pub mod ix; // Stores a DEFINE INDEX config definition
|
|
||||||
pub mod kv; // Stores the key prefix for all keys
|
|
||||||
pub mod lq; // Stores a LIVE SELECT query definition on the database
|
|
||||||
pub mod lv; // Stores a LIVE SELECT query definition on the table
|
|
||||||
pub mod namespace; // Stores the key prefix for all keys under a namespace
|
|
||||||
pub mod nl; // Stores a DEFINE LOGIN ON NAMESPACE config definition
|
|
||||||
pub mod ns; // Stores a DEFINE NAMESPACE config definition
|
|
||||||
pub mod nt; // Stores a DEFINE TOKEN ON NAMESPACE config definition
|
|
||||||
pub mod pa; // Stores a DEFINE PARAM config definition
|
|
||||||
pub mod sc; // Stores a DEFINE SCOPE config definition
|
|
||||||
pub mod scope; // Stores the key prefix for all keys under a scope
|
|
||||||
pub mod st; // Stores a DEFINE TOKEN ON SCOPE config definition
|
|
||||||
pub mod table; // Stores the key prefix for all keys under a table
|
|
||||||
pub mod tb; // Stores a DEFINE TABLE config definition
|
|
||||||
pub mod thing; // Stores a record id
|
|
||||||
|
|
||||||
const CHAR_PATH: u8 = 0xb1; // ±
|
|
||||||
const CHAR_INDEX: u8 = 0xa4; // ¤
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
|
//! Stores the key prefix for all keys under a namespace
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Namespace<'a> {
|
pub struct All<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(ns: &str) -> Namespace<'_> {
|
pub fn new(ns: &str) -> All<'_> {
|
||||||
Namespace::new(ns)
|
All::new(ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Namespace<'a> {
|
impl<'a> All<'a> {
|
||||||
pub fn new(ns: &'a str) -> Self {
|
pub fn new(ns: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
|
@ -28,13 +29,13 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Namespace::new(
|
let val = All::new(
|
||||||
"testns",
|
"testns",
|
||||||
);
|
);
|
||||||
let enc = Namespace::encode(&val).unwrap();
|
let enc = All::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0");
|
assert_eq!(enc, b"/*testns\0");
|
||||||
|
|
||||||
let dec = Namespace::decode(&enc).unwrap();
|
let dec = All::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE DATABASE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -17,13 +18,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str) -> Db<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b'b', 0x00]);
|
k.extend_from_slice(&[b'!', b'd', b'b', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'd', b'b', 0xff]);
|
k.extend_from_slice(&[b'!', b'd', b'b', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
|
//! Stores a DEFINE LOGIN ON NAMESPACE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Nl<'a> {
|
pub struct Lg<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -12,31 +13,31 @@ pub struct Nl<'a> {
|
||||||
pub us: &'a str,
|
pub us: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, us: &'a str) -> Nl<'a> {
|
pub fn new<'a>(ns: &'a str, us: &'a str) -> Lg<'a> {
|
||||||
Nl::new(ns, us)
|
Lg::new(ns, us)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b'l', 0x00]);
|
k.extend_from_slice(&[b'!', b'l', b'g', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b'l', 0xff]);
|
k.extend_from_slice(&[b'!', b'l', b'g', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Nl<'a> {
|
impl<'a> Lg<'a> {
|
||||||
pub fn new(ns: &'a str, us: &'a str) -> Self {
|
pub fn new(ns: &'a str, us: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
_a: b'*',
|
_a: b'*',
|
||||||
ns,
|
ns,
|
||||||
_b: b'!',
|
_b: b'!',
|
||||||
_c: b'n',
|
_c: b'l',
|
||||||
_d: b'l',
|
_d: b'g',
|
||||||
us,
|
us,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,14 +49,14 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Nl::new(
|
let val = Lg::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testus",
|
"testus",
|
||||||
);
|
);
|
||||||
let enc = Nl::encode(&val).unwrap();
|
let enc = Lg::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0!nltestus\0");
|
assert_eq!(enc, b"/*testns\0!lgtestus\0");
|
||||||
|
|
||||||
let dec = Nl::decode(&enc).unwrap();
|
let dec = Lg::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
4
lib/src/key/namespace/mod.rs
Normal file
4
lib/src/key/namespace/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod db;
|
||||||
|
pub mod lg;
|
||||||
|
pub mod tk;
|
|
@ -1,8 +1,9 @@
|
||||||
|
//! Stores a DEFINE TOKEN ON NAMESPACE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Nt<'a> {
|
pub struct Tk<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -12,31 +13,31 @@ pub struct Nt<'a> {
|
||||||
pub tk: &'a str,
|
pub tk: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, tk: &'a str) -> Nt<'a> {
|
pub fn new<'a>(ns: &'a str, tk: &'a str) -> Tk<'a> {
|
||||||
Nt::new(ns, tk)
|
Tk::new(ns, tk)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b't', 0x00]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str) -> Vec<u8> {
|
||||||
let mut k = super::namespace::new(ns).encode().unwrap();
|
let mut k = super::all::new(ns).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b't', 0xff]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Nt<'a> {
|
impl<'a> Tk<'a> {
|
||||||
pub fn new(ns: &'a str, tk: &'a str) -> Self {
|
pub fn new(ns: &'a str, tk: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
_a: b'*',
|
_a: b'*',
|
||||||
ns,
|
ns,
|
||||||
_b: b'!',
|
_b: b'!',
|
||||||
_c: b'n',
|
_c: b't',
|
||||||
_d: b't',
|
_d: b'k',
|
||||||
tk,
|
tk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,13 +49,13 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Nt::new(
|
let val = Tk::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testtk",
|
"testtk",
|
||||||
);
|
);
|
||||||
let enc = Nt::encode(&val).unwrap();
|
let enc = Tk::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0!nttesttk\0");
|
assert_eq!(enc, b"/*testns\0!tktesttk\0");
|
||||||
let dec = Nt::decode(&enc).unwrap();
|
let dec = Tk::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
45
lib/src/key/node/all.rs
Normal file
45
lib/src/key/node/all.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
//! Stores the key prefix for all nodes
|
||||||
|
use derive::Key;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
|
pub struct All {
|
||||||
|
__: u8,
|
||||||
|
_a: u8,
|
||||||
|
#[serde(with = "uuid::serde::compact")]
|
||||||
|
pub nd: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(nd: Uuid) -> All {
|
||||||
|
All::new(nd)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl All {
|
||||||
|
pub fn new(nd: Uuid) -> Self {
|
||||||
|
Self {
|
||||||
|
__: b'/',
|
||||||
|
_a: b'$',
|
||||||
|
nd,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn key() {
|
||||||
|
use super::*;
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let nd = Uuid::from_bytes([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
|
||||||
|
#[rustfmt::skip]
|
||||||
|
let val = All::new(
|
||||||
|
nd,
|
||||||
|
);
|
||||||
|
let enc = All::encode(&val).unwrap();
|
||||||
|
assert_eq!(enc, b"/$\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10");
|
||||||
|
|
||||||
|
let dec = All::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a LIVE SELECT query definition on the cluster
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -53,7 +54,7 @@ impl<'a> Lq<'a> {
|
||||||
db,
|
db,
|
||||||
_f: b'!',
|
_f: b'!',
|
||||||
_g: b'l',
|
_g: b'l',
|
||||||
_h: b'v',
|
_h: b'q',
|
||||||
lq,
|
lq,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,7 @@ mod tests {
|
||||||
let lv = Uuid::from_bytes([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20]);
|
let lv = Uuid::from_bytes([0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20]);
|
||||||
let val = Lq::new(nd, "testns", "testdb", lv);
|
let val = Lq::new(nd, "testns", "testdb", lv);
|
||||||
let enc = Lq::encode(&val).unwrap();
|
let enc = Lq::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/!nd\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10*testns\x00*testdb\x00!lv\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20" );
|
assert_eq!(enc, b"/!nd\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10*testns\x00*testdb\x00!lq\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20" );
|
||||||
|
|
||||||
let dec = Lq::decode(&enc).unwrap();
|
let dec = Lq::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
2
lib/src/key/node/mod.rs
Normal file
2
lib/src/key/node/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod lq;
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores the key prefix for all keys
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::dbs::cl::{KeyTimestamp, Timestamp};
|
//! Stores a heartbeat per registered cluster node
|
||||||
|
use crate::dbs::node::{KeyTimestamp, Timestamp};
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -29,7 +30,7 @@ impl Hb {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix() -> Vec<u8> {
|
pub fn prefix() -> Vec<u8> {
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = crate::key::root::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'h', b'b', 0x00]);
|
k.extend_from_slice(&[b'!', b'h', b'b', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,7 @@ impl Hb {
|
||||||
let tskey: KeyTimestamp = KeyTimestamp {
|
let tskey: KeyTimestamp = KeyTimestamp {
|
||||||
value: ts.value + 1,
|
value: ts.value + 1,
|
||||||
};
|
};
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = crate::key::root::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'h', b'b']);
|
k.extend_from_slice(&[b'!', b'h', b'b']);
|
||||||
k.extend_from_slice(tskey.encode().unwrap().as_ref());
|
k.extend_from_slice(tskey.encode().unwrap().as_ref());
|
||||||
k
|
k
|
||||||
|
@ -60,14 +61,14 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Hb::new(
|
let val = Hb::new(
|
||||||
Timestamp { value: 123 },
|
Timestamp { value: 123 },
|
||||||
Uuid::from_bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
Uuid::from_bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
||||||
);
|
);
|
||||||
let enc = Hb::encode(&val).unwrap();
|
let enc = Hb::encode(&val).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
enc,
|
enc,
|
||||||
b"/!hb\x00\x00\x00\x00\x00\x00\x00\x7b/\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10");
|
b"/!hb\x00\x00\x00\x00\x00\x00\x00\x7b/\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10");
|
||||||
let dec = Hb::decode(&enc).unwrap();
|
let dec = Hb::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
4
lib/src/key/root/mod.rs
Normal file
4
lib/src/key/root/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod hb;
|
||||||
|
pub mod nd;
|
||||||
|
pub mod ns;
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores cluster membership information
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -5,7 +6,7 @@ use uuid::Uuid;
|
||||||
// Represents cluster information.
|
// Represents cluster information.
|
||||||
// In the future, this could also include broadcast addresses and other information.
|
// In the future, this could also include broadcast addresses and other information.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Cl {
|
pub struct Nd {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
_b: u8,
|
_b: u8,
|
||||||
|
@ -14,26 +15,26 @@ pub struct Cl {
|
||||||
pub nd: Uuid,
|
pub nd: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cl {
|
impl Nd {
|
||||||
pub fn new(nd: Uuid) -> Self {
|
pub fn new(nd: Uuid) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
_a: b'!',
|
_a: b'!',
|
||||||
_b: b'c',
|
_b: b'n',
|
||||||
_c: b'l',
|
_c: b'd',
|
||||||
nd,
|
nd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix() -> Vec<u8> {
|
pub fn prefix() -> Vec<u8> {
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = crate::key::root::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'l', 0x00]);
|
k.extend_from_slice(&[b'!', b'n', b'd', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix() -> Vec<u8> {
|
pub fn suffix() -> Vec<u8> {
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = crate::key::root::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'c', b'l', 0xff]);
|
k.extend_from_slice(&[b'!', b'n', b'd', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,21 +44,21 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
let val = Cl::new(Uuid::default());
|
let val = Nd::new(Uuid::default());
|
||||||
let enc = Cl::encode(&val).unwrap();
|
let enc = Nd::encode(&val).unwrap();
|
||||||
let dec = Cl::decode(&enc).unwrap();
|
let dec = Nd::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prefix() {
|
fn test_prefix() {
|
||||||
let val = super::Cl::prefix();
|
let val = super::Nd::prefix();
|
||||||
assert_eq!(val, b"/!cl\0")
|
assert_eq!(val, b"/!nd\0")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_suffix() {
|
fn test_suffix() {
|
||||||
let val = super::Cl::suffix();
|
let val = super::Nd::suffix();
|
||||||
assert_eq!(val, b"/!cl\xff")
|
assert_eq!(val, b"/!nd\xff")
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a DEFINE NAMESPACE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -15,13 +16,13 @@ pub fn new(ns: &str) -> Ns<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix() -> Vec<u8> {
|
pub fn prefix() -> Vec<u8> {
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = super::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b's', 0x00]);
|
k.extend_from_slice(&[b'!', b'n', b's', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix() -> Vec<u8> {
|
pub fn suffix() -> Vec<u8> {
|
||||||
let mut k = super::kv::new().encode().unwrap();
|
let mut k = super::all::new().encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'n', b's', 0xff]);
|
k.extend_from_slice(&[b'!', b'n', b's', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
@ -44,9 +45,9 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = Ns::new(
|
let val = Ns::new(
|
||||||
"testns",
|
"testns",
|
||||||
);
|
);
|
||||||
let enc = Ns::encode(&val).unwrap();
|
let enc = Ns::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/!nstestns\0");
|
assert_eq!(enc, b"/!nstestns\0");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::key::CHAR_PATH;
|
//! Stores the key prefix for all keys under a scope
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ impl<'a> Scope<'a> {
|
||||||
ns,
|
ns,
|
||||||
_b: b'*',
|
_b: b'*',
|
||||||
db,
|
db,
|
||||||
_c: CHAR_PATH,
|
_c: super::CHAR,
|
||||||
sc,
|
sc,
|
||||||
}
|
}
|
||||||
}
|
}
|
4
lib/src/key/scope/mod.rs
Normal file
4
lib/src/key/scope/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod tk;
|
||||||
|
|
||||||
|
pub(self) const CHAR: u8 = 0xb1; // ±
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::key::CHAR_PATH;
|
//! Stores a DEFINE TOKEN ON SCOPE config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct St<'a> {
|
pub struct Tk<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -17,23 +17,23 @@ pub struct St<'a> {
|
||||||
pub tk: &'a str,
|
pub tk: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> St<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> Tk<'a> {
|
||||||
St::new(ns, db, sc, tk)
|
Tk::new(ns, db, sc, tk)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, sc: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, sc: &str) -> Vec<u8> {
|
||||||
let mut k = super::scope::new(ns, db, sc).encode().unwrap();
|
let mut k = super::all::new(ns, db, sc).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b's', b't', 0x00]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, sc: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, sc: &str) -> Vec<u8> {
|
||||||
let mut k = super::scope::new(ns, db, sc).encode().unwrap();
|
let mut k = super::all::new(ns, db, sc).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b's', b't', 0xff]);
|
k.extend_from_slice(&[b'!', b't', b'k', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> St<'a> {
|
impl<'a> Tk<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> Self {
|
pub fn new(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
|
@ -41,11 +41,11 @@ impl<'a> St<'a> {
|
||||||
ns,
|
ns,
|
||||||
_b: b'*',
|
_b: b'*',
|
||||||
db,
|
db,
|
||||||
_c: CHAR_PATH,
|
_c: super::CHAR,
|
||||||
sc,
|
sc,
|
||||||
_d: b'!',
|
_d: b'!',
|
||||||
_e: b's',
|
_e: b't',
|
||||||
_f: b't',
|
_f: b'k',
|
||||||
tk,
|
tk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,16 +57,16 @@ mod tests {
|
||||||
fn key() {
|
fn key() {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let val = St::new(
|
let val = Tk::new(
|
||||||
"testns",
|
"testns",
|
||||||
"testdb",
|
"testdb",
|
||||||
"testsc",
|
"testsc",
|
||||||
"testtk",
|
"testtk",
|
||||||
);
|
);
|
||||||
let enc = St::encode(&val).unwrap();
|
let enc = Tk::encode(&val).unwrap();
|
||||||
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0!sttesttk\0");
|
assert_eq!(enc, b"/*testns\0*testdb\0\xb1testsc\0!tktesttk\0");
|
||||||
|
|
||||||
let dec = St::decode(&enc).unwrap();
|
let dec = Tk::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores the key prefix for all keys under a table
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE EVENT config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -21,13 +22,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Ev<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'e', b'v', 0x00]);
|
k.extend_from_slice(&[b'!', b'e', b'v', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'e', b'v', 0xff]);
|
k.extend_from_slice(&[b'!', b'e', b'v', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE FIELD config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -21,13 +22,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, fd: &'a str) -> Fd<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b'd', 0x00]);
|
k.extend_from_slice(&[b'!', b'f', b'd', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b'd', 0xff]);
|
k.extend_from_slice(&[b'!', b'f', b'd', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE TABLE AS config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -21,13 +22,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ft: &'a str) -> Ft<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b't', 0x00]);
|
k.extend_from_slice(&[b'!', b'f', b't', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'f', b't', 0xff]);
|
k.extend_from_slice(&[b'!', b'f', b't', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// Stores a DEFINE INDEX config definition
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -21,13 +22,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Ix<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'i', b'x', 0x00]);
|
k.extend_from_slice(&[b'!', b'i', b'x', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'i', b'x', 0xff]);
|
k.extend_from_slice(&[b'!', b'i', b'x', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
|
//! Stores a LIVE SELECT query definition on the table
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
|
||||||
pub struct Lv<'a> {
|
pub struct Lq<'a> {
|
||||||
__: u8,
|
__: u8,
|
||||||
_a: u8,
|
_a: u8,
|
||||||
pub ns: &'a str,
|
pub ns: &'a str,
|
||||||
|
@ -15,27 +16,27 @@ pub struct Lv<'a> {
|
||||||
_e: u8,
|
_e: u8,
|
||||||
_f: u8,
|
_f: u8,
|
||||||
#[serde(with = "uuid::serde::compact")]
|
#[serde(with = "uuid::serde::compact")]
|
||||||
pub lv: Uuid,
|
pub lq: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, lv: Uuid) -> Lv<'a> {
|
pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, lq: Uuid) -> Lq<'a> {
|
||||||
Lv::new(ns, db, tb, lv)
|
Lq::new(ns, db, tb, lq)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'l', b'v', 0x00]);
|
k.extend_from_slice(&[b'!', b'l', b'q', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = super::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'!', b'l', b'v', 0xff]);
|
k.extend_from_slice(&[b'!', b'l', b'q', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Lv<'a> {
|
impl<'a> Lq<'a> {
|
||||||
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, lv: Uuid) -> Self {
|
pub fn new(ns: &'a str, db: &'a str, tb: &'a str, lq: Uuid) -> Self {
|
||||||
Self {
|
Self {
|
||||||
__: b'/',
|
__: b'/',
|
||||||
_a: b'*',
|
_a: b'*',
|
||||||
|
@ -46,8 +47,8 @@ impl<'a> Lv<'a> {
|
||||||
tb,
|
tb,
|
||||||
_d: b'!',
|
_d: b'!',
|
||||||
_e: b'l',
|
_e: b'l',
|
||||||
_f: b'v',
|
_f: b'q',
|
||||||
lv,
|
lq,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,27 +62,27 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let live_query_id = Uuid::from_bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
let live_query_id = Uuid::from_bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
|
||||||
let val = Lv::new("testns", "testdb", "testtb", live_query_id);
|
let val = Lq::new("testns", "testdb", "testtb", live_query_id);
|
||||||
let enc = Lv::encode(&val).unwrap();
|
let enc = Lq::encode(&val).unwrap();
|
||||||
println!("{:?}", debug::sprint_key(&enc));
|
println!("{:?}", debug::sprint_key(&enc));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
enc,
|
enc,
|
||||||
b"/*testns\x00*testdb\x00*testtb\x00!lv\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
b"/*testns\x00*testdb\x00*testtb\x00!lq\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
||||||
);
|
);
|
||||||
|
|
||||||
let dec = Lv::decode(&enc).unwrap();
|
let dec = Lq::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prefix() {
|
fn prefix() {
|
||||||
let val = super::prefix("testns", "testdb", "testtb");
|
let val = super::prefix("testns", "testdb", "testtb");
|
||||||
assert_eq!(val, b"/*testns\x00*testdb\x00*testtb\x00!lv\x00")
|
assert_eq!(val, b"/*testns\x00*testdb\x00*testtb\x00!lq\x00")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn suffix() {
|
fn suffix() {
|
||||||
let val = super::suffix("testns", "testdb", "testtb");
|
let val = super::suffix("testns", "testdb", "testtb");
|
||||||
assert_eq!(val, b"/*testns\x00*testdb\x00*testtb\x00!lv\xff")
|
assert_eq!(val, b"/*testns\x00*testdb\x00*testtb\x00!lq\xff")
|
||||||
}
|
}
|
||||||
}
|
}
|
6
lib/src/key/table/mod.rs
Normal file
6
lib/src/key/table/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pub mod all;
|
||||||
|
pub mod ev;
|
||||||
|
pub mod fd;
|
||||||
|
pub mod ft;
|
||||||
|
pub mod ix;
|
||||||
|
pub mod lq;
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Stores a record document
|
||||||
use crate::sql::id::Id;
|
use crate::sql::id::Id;
|
||||||
use derive::Key;
|
use derive::Key;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -20,13 +21,13 @@ pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, id: &Id) -> Thing<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = crate::key::table::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'*', 0x00]);
|
k.extend_from_slice(&[b'*', 0x00]);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
|
||||||
let mut k = super::table::new(ns, db, tb).encode().unwrap();
|
let mut k = crate::key::table::all::new(ns, db, tb).encode().unwrap();
|
||||||
k.extend_from_slice(&[b'*', 0xff]);
|
k.extend_from_slice(&[b'*', 0xff]);
|
||||||
k
|
k
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::ctx::Context;
|
use crate::ctx::Context;
|
||||||
use crate::dbs::cl::Timestamp;
|
use crate::dbs::node::Timestamp;
|
||||||
use crate::dbs::Attach;
|
use crate::dbs::Attach;
|
||||||
use crate::dbs::Executor;
|
use crate::dbs::Executor;
|
||||||
use crate::dbs::Notification;
|
use crate::dbs::Notification;
|
||||||
|
@ -8,9 +8,7 @@ use crate::dbs::Response;
|
||||||
use crate::dbs::Session;
|
use crate::dbs::Session;
|
||||||
use crate::dbs::Variables;
|
use crate::dbs::Variables;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::key::hb::Hb;
|
use crate::key::root::hb::Hb;
|
||||||
use crate::key::lq;
|
|
||||||
use crate::key::lv::Lv;
|
|
||||||
use crate::sql;
|
use crate::sql;
|
||||||
use crate::sql::Query;
|
use crate::sql::Query;
|
||||||
use crate::sql::Value;
|
use crate::sql::Value;
|
||||||
|
@ -30,7 +28,7 @@ use super::tx::Transaction;
|
||||||
/// Not a stored struct; Used only in this module
|
/// Not a stored struct; Used only in this module
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct LqValue {
|
pub struct LqValue {
|
||||||
pub cl: Uuid,
|
pub nd: Uuid,
|
||||||
pub ns: String,
|
pub ns: String,
|
||||||
pub db: String,
|
pub db: String,
|
||||||
pub tb: String,
|
pub tb: String,
|
||||||
|
@ -324,7 +322,7 @@ impl Datastore {
|
||||||
node_id: &Uuid,
|
node_id: &Uuid,
|
||||||
timestamp: &Timestamp,
|
timestamp: &Timestamp,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
tx.set_cl(*node_id).await?;
|
tx.set_nd(*node_id).await?;
|
||||||
tx.set_hb(timestamp.clone(), *node_id).await?;
|
tx.set_hb(timestamp.clone(), *node_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -340,7 +338,7 @@ impl Datastore {
|
||||||
let mut nodes = vec![];
|
let mut nodes = vec![];
|
||||||
for hb in hbs {
|
for hb in hbs {
|
||||||
trace!("Deleting node {}", &hb.nd);
|
trace!("Deleting node {}", &hb.nd);
|
||||||
tx.del_cl(hb.nd).await?;
|
tx.del_nd(hb.nd).await?;
|
||||||
nodes.push(hb.nd);
|
nodes.push(hb.nd);
|
||||||
}
|
}
|
||||||
Ok(nodes)
|
Ok(nodes)
|
||||||
|
@ -366,7 +364,7 @@ impl Datastore {
|
||||||
trace!("Found {} LQ entries for {:?}", node_lqs.len(), nd);
|
trace!("Found {} LQ entries for {:?}", node_lqs.len(), nd);
|
||||||
for lq in node_lqs {
|
for lq in node_lqs {
|
||||||
trace!("Archiving query {:?}", &lq);
|
trace!("Archiving query {:?}", &lq);
|
||||||
let node_archived_lqs = self.archive_lv_for_node(tx, &lq.cl, this_node_id).await?;
|
let node_archived_lqs = self.archive_lv_for_node(tx, &lq.nd, this_node_id).await?;
|
||||||
for lq_value in node_archived_lqs {
|
for lq_value in node_archived_lqs {
|
||||||
archived.push(lq_value);
|
archived.push(lq_value);
|
||||||
}
|
}
|
||||||
|
@ -382,9 +380,11 @@ impl Datastore {
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
for lq in archived {
|
for lq in archived {
|
||||||
// Delete the cluster key, used for finding LQ associated with a node
|
// Delete the cluster key, used for finding LQ associated with a node
|
||||||
tx.del(lq::new(lq.cl, lq.ns.as_str(), lq.db.as_str(), lq.lq)).await?;
|
let key = crate::key::node::lq::new(lq.nd, &lq.ns, &lq.db, lq.lq);
|
||||||
|
tx.del(key).await?;
|
||||||
// Delete the table key, used for finding LQ associated with a table
|
// Delete the table key, used for finding LQ associated with a table
|
||||||
tx.del(Lv::new(lq.ns.as_str(), lq.db.as_str(), lq.tb.as_str(), lq.lq)).await?;
|
let key = crate::key::table::lq::new(&lq.ns, &lq.db, &lq.tb, lq.lq);
|
||||||
|
tx.del(key).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ impl Datastore {
|
||||||
let mut archived: Vec<LqValue> = vec![];
|
let mut archived: Vec<LqValue> = vec![];
|
||||||
for hb in dead_heartbeats {
|
for hb in dead_heartbeats {
|
||||||
let new_archived = self.archive_lv_for_node(tx, &hb.nd, this_node_id).await?;
|
let new_archived = self.archive_lv_for_node(tx, &hb.nd, this_node_id).await?;
|
||||||
tx.del_cl(hb.nd).await?;
|
tx.del_nd(hb.nd).await?;
|
||||||
trace!("Deleted node {}", hb.nd);
|
trace!("Deleted node {}", hb.nd);
|
||||||
for lq_value in new_archived {
|
for lq_value in new_archived {
|
||||||
archived.push(lq_value);
|
archived.push(lq_value);
|
||||||
|
@ -441,7 +441,7 @@ impl Datastore {
|
||||||
let dead = tx.scan_hb(ts, limit).await?;
|
let dead = tx.scan_hb(ts, limit).await?;
|
||||||
tx.delr_hb(dead.clone(), 1000).await?;
|
tx.delr_hb(dead.clone(), 1000).await?;
|
||||||
for dead_node in dead.clone() {
|
for dead_node in dead.clone() {
|
||||||
tx.del_cl(dead_node.nd).await?;
|
tx.del_nd(dead_node.nd).await?;
|
||||||
}
|
}
|
||||||
Ok::<Vec<Hb>, Error>(dead)
|
Ok::<Vec<Hb>, Error>(dead)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::dbs::cl::Timestamp;
|
use crate::dbs::node::Timestamp;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
|
||||||
pub struct TestContext {
|
pub struct TestContext {
|
||||||
|
|
|
@ -15,7 +15,7 @@ async fn scan_node_lq() {
|
||||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
|
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
|
||||||
0x1F,
|
0x1F,
|
||||||
]);
|
]);
|
||||||
let key = crate::key::lq::new(node_id, namespace, database, live_query_id);
|
let key = crate::key::node::lq::new(node_id, namespace, database, live_query_id);
|
||||||
trace!(
|
trace!(
|
||||||
"Inserting key: {}",
|
"Inserting key: {}",
|
||||||
key.encode()
|
key.encode()
|
||||||
|
@ -32,7 +32,7 @@ async fn scan_node_lq() {
|
||||||
let res = tx.scan_lq(&node_id, 100).await.unwrap();
|
let res = tx.scan_lq(&node_id, 100).await.unwrap();
|
||||||
assert_eq!(res.len(), 1);
|
assert_eq!(res.len(), 1);
|
||||||
for val in res {
|
for val in res {
|
||||||
assert_eq!(val.cl, node_id);
|
assert_eq!(val.nd, node_id);
|
||||||
assert_eq!(val.ns, namespace);
|
assert_eq!(val.ns, namespace);
|
||||||
assert_eq!(val.db, database);
|
assert_eq!(val.db, database);
|
||||||
assert_eq!(val.lq, live_query_id);
|
assert_eq!(val.lq, live_query_id);
|
||||||
|
|
|
@ -16,7 +16,7 @@ mod mem {
|
||||||
include!("helper.rs");
|
include!("helper.rs");
|
||||||
include!("cluster_init.rs");
|
include!("cluster_init.rs");
|
||||||
include!("lq.rs");
|
include!("lq.rs");
|
||||||
include!("lv.rs");
|
include!("nq.rs");
|
||||||
include!("raw.rs");
|
include!("raw.rs");
|
||||||
include!("snapshot.rs");
|
include!("snapshot.rs");
|
||||||
include!("tb.rs");
|
include!("tb.rs");
|
||||||
|
@ -43,7 +43,7 @@ mod rocksdb {
|
||||||
include!("helper.rs");
|
include!("helper.rs");
|
||||||
include!("cluster_init.rs");
|
include!("cluster_init.rs");
|
||||||
include!("lq.rs");
|
include!("lq.rs");
|
||||||
include!("lv.rs");
|
include!("nq.rs");
|
||||||
include!("raw.rs");
|
include!("raw.rs");
|
||||||
include!("snapshot.rs");
|
include!("snapshot.rs");
|
||||||
include!("tb.rs");
|
include!("tb.rs");
|
||||||
|
@ -72,7 +72,7 @@ mod speedb {
|
||||||
include!("helper.rs");
|
include!("helper.rs");
|
||||||
include!("cluster_init.rs");
|
include!("cluster_init.rs");
|
||||||
include!("lq.rs");
|
include!("lq.rs");
|
||||||
include!("lv.rs");
|
include!("nq.rs");
|
||||||
include!("raw.rs");
|
include!("raw.rs");
|
||||||
include!("snapshot.rs");
|
include!("snapshot.rs");
|
||||||
include!("tb.rs");
|
include!("tb.rs");
|
||||||
|
@ -105,7 +105,7 @@ mod tikv {
|
||||||
include!("cluster_init.rs");
|
include!("cluster_init.rs");
|
||||||
include!("helper.rs");
|
include!("helper.rs");
|
||||||
include!("lq.rs");
|
include!("lq.rs");
|
||||||
include!("lv.rs");
|
include!("nq.rs");
|
||||||
include!("raw.rs");
|
include!("raw.rs");
|
||||||
include!("snapshot.rs");
|
include!("snapshot.rs");
|
||||||
include!("tb.rs");
|
include!("tb.rs");
|
||||||
|
@ -138,7 +138,7 @@ mod fdb {
|
||||||
include!("cluster_init.rs");
|
include!("cluster_init.rs");
|
||||||
include!("helper.rs");
|
include!("helper.rs");
|
||||||
include!("lq.rs");
|
include!("lq.rs");
|
||||||
include!("lv.rs");
|
include!("nq.rs");
|
||||||
include!("raw.rs");
|
include!("raw.rs");
|
||||||
include!("snapshot.rs");
|
include!("snapshot.rs");
|
||||||
include!("tb.rs");
|
include!("tb.rs");
|
||||||
|
|
|
@ -12,14 +12,14 @@ async fn archive_lv_for_node_archives() {
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
|
||||||
0x0F,
|
0x0F,
|
||||||
]);
|
]);
|
||||||
tx.set_cl(node_id).await.unwrap();
|
tx.set_nd(node_id).await.unwrap();
|
||||||
|
|
||||||
let lv_id = Uuid::from_bytes([
|
let lv_id = Uuid::from_bytes([
|
||||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
|
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
|
||||||
0x1F,
|
0x1F,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let key = crate::key::lq::new(node_id, namespace, database, lv_id);
|
let key = crate::key::node::lq::new(node_id, namespace, database, lv_id);
|
||||||
tx.putc(key, table, None).await.unwrap();
|
tx.putc(key, table, None).await.unwrap();
|
||||||
|
|
||||||
let (_, mut stm) = live(format!("LIVE SELECT * FROM {}", table).as_str()).unwrap();
|
let (_, mut stm) = live(format!("LIVE SELECT * FROM {}", table).as_str()).unwrap();
|
||||||
|
@ -37,7 +37,7 @@ async fn archive_lv_for_node_archives() {
|
||||||
let mut tx = test.db.transaction(true, false).await.unwrap();
|
let mut tx = test.db.transaction(true, false).await.unwrap();
|
||||||
let results = test.db.archive_lv_for_node(&mut tx, &node_id, &this_node_id).await.unwrap();
|
let results = test.db.archive_lv_for_node(&mut tx, &node_id, &this_node_id).await.unwrap();
|
||||||
assert_eq!(results.len(), 1);
|
assert_eq!(results.len(), 1);
|
||||||
assert_eq!(results[0].cl, node_id);
|
assert_eq!(results[0].nd, node_id);
|
||||||
assert_eq!(results[0].ns, namespace);
|
assert_eq!(results[0].ns, namespace);
|
||||||
assert_eq!(results[0].db, database);
|
assert_eq!(results[0].db, database);
|
||||||
assert_eq!(results[0].tb, table);
|
assert_eq!(results[0].tb, table);
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::key::tb;
|
use crate::key::database::tb;
|
||||||
use crate::key::tb::Tb;
|
use crate::key::database::tb::Tb;
|
||||||
use crate::sql::statements::DefineTableStatement;
|
use crate::sql::statements::DefineTableStatement;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -2,13 +2,9 @@ use super::kv::Add;
|
||||||
use super::kv::Convert;
|
use super::kv::Convert;
|
||||||
use super::Key;
|
use super::Key;
|
||||||
use super::Val;
|
use super::Val;
|
||||||
use crate::dbs::cl::ClusterMembership;
|
use crate::dbs::node::ClusterMembership;
|
||||||
use crate::dbs::cl::Timestamp;
|
use crate::dbs::node::Timestamp;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::key::hb::Hb;
|
|
||||||
use crate::key::lq::Lq;
|
|
||||||
use crate::key::lv::Lv;
|
|
||||||
use crate::key::{lq, thing};
|
|
||||||
use crate::kvs::cache::Cache;
|
use crate::kvs::cache::Cache;
|
||||||
use crate::kvs::cache::Entry;
|
use crate::kvs::cache::Entry;
|
||||||
use crate::kvs::LqValue;
|
use crate::kvs::LqValue;
|
||||||
|
@ -798,9 +794,9 @@ impl Transaction {
|
||||||
// Register cluster membership
|
// Register cluster membership
|
||||||
// NOTE: Setting cluster membership sets the heartbeat
|
// NOTE: Setting cluster membership sets the heartbeat
|
||||||
// Remember to set the heartbeat as well
|
// Remember to set the heartbeat as well
|
||||||
pub async fn set_cl(&mut self, id: Uuid) -> Result<(), Error> {
|
pub async fn set_nd(&mut self, id: Uuid) -> Result<(), Error> {
|
||||||
let key = crate::key::cl::Cl::new(id);
|
let key = crate::key::root::nd::Nd::new(id);
|
||||||
match self.get_cl(id).await? {
|
match self.get_nd(id).await? {
|
||||||
Some(_) => Err(Error::ClAlreadyExists {
|
Some(_) => Err(Error::ClAlreadyExists {
|
||||||
value: id.to_string(),
|
value: id.to_string(),
|
||||||
}),
|
}),
|
||||||
|
@ -816,8 +812,8 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve cluster information
|
// Retrieve cluster information
|
||||||
pub async fn get_cl(&mut self, id: Uuid) -> Result<Option<ClusterMembership>, Error> {
|
pub async fn get_nd(&mut self, id: Uuid) -> Result<Option<ClusterMembership>, Error> {
|
||||||
let key = crate::key::cl::Cl::new(id);
|
let key = crate::key::root::nd::Nd::new(id);
|
||||||
let val = self.get(key).await?;
|
let val = self.get(key).await?;
|
||||||
match val {
|
match val {
|
||||||
Some(v) => Ok(Some::<ClusterMembership>(v.into())),
|
Some(v) => Ok(Some::<ClusterMembership>(v.into())),
|
||||||
|
@ -835,7 +831,7 @@ impl Transaction {
|
||||||
|
|
||||||
// Set heartbeat
|
// Set heartbeat
|
||||||
pub async fn set_hb(&mut self, timestamp: Timestamp, id: Uuid) -> Result<(), Error> {
|
pub async fn set_hb(&mut self, timestamp: Timestamp, id: Uuid) -> Result<(), Error> {
|
||||||
let key = Hb::new(timestamp.clone(), id);
|
let key = crate::key::root::hb::Hb::new(timestamp.clone(), id);
|
||||||
// We do not need to do a read, we always want to overwrite
|
// We do not need to do a read, we always want to overwrite
|
||||||
self.put(
|
self.put(
|
||||||
key,
|
key,
|
||||||
|
@ -849,30 +845,34 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a cluster registration entry
|
// Delete a cluster registration entry
|
||||||
pub async fn del_cl(&mut self, node: uuid::Uuid) -> Result<(), Error> {
|
pub async fn del_nd(&mut self, node: Uuid) -> Result<(), Error> {
|
||||||
let key = crate::key::cl::Cl::new(node);
|
let key = crate::key::root::nd::Nd::new(node);
|
||||||
self.del(key).await
|
self.del(key).await
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the live query notification registry on the table
|
// Delete the live query notification registry on the table
|
||||||
// Return the Table ID
|
// Return the Table ID
|
||||||
pub async fn del_cllv(&mut self, cl: &Uuid) -> Result<Uuid, Error> {
|
pub async fn del_ndlv(&mut self, nd: &Uuid) -> Result<Uuid, Error> {
|
||||||
// This isn't implemented because it is covered by del_cl
|
// This isn't implemented because it is covered by del_nd
|
||||||
// Will add later for remote node kill
|
// Will add later for remote node kill
|
||||||
Err(Error::ClNotFound {
|
Err(Error::NdNotFound {
|
||||||
value: format!("Missing cluster {:?}", cl),
|
value: format!("Missing cluster node {:?}", nd),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scans up until the heartbeat timestamp and returns the discovered nodes
|
// Scans up until the heartbeat timestamp and returns the discovered nodes
|
||||||
pub async fn scan_hb(&mut self, time_to: &Timestamp, limit: u32) -> Result<Vec<Hb>, Error> {
|
pub async fn scan_hb(
|
||||||
let beg = crate::key::hb::Hb::prefix();
|
&mut self,
|
||||||
let end = crate::key::hb::Hb::suffix(time_to);
|
time_to: &Timestamp,
|
||||||
|
limit: u32,
|
||||||
|
) -> Result<Vec<crate::key::root::hb::Hb>, Error> {
|
||||||
|
let beg = crate::key::root::hb::Hb::prefix();
|
||||||
|
let end = crate::key::root::hb::Hb::suffix(time_to);
|
||||||
trace!("Scan start: {} ({:?})", String::from_utf8_lossy(&beg).to_string(), &beg);
|
trace!("Scan start: {} ({:?})", String::from_utf8_lossy(&beg).to_string(), &beg);
|
||||||
trace!("Scan end: {} ({:?})", String::from_utf8_lossy(&end).to_string(), &end);
|
trace!("Scan end: {} ({:?})", String::from_utf8_lossy(&end).to_string(), &end);
|
||||||
let mut nxt: Option<Key> = None;
|
let mut nxt: Option<Key> = None;
|
||||||
let mut num = limit;
|
let mut num = limit;
|
||||||
let mut out: Vec<Hb> = vec![];
|
let mut out: Vec<crate::key::root::hb::Hb> = vec![];
|
||||||
// Start processing
|
// Start processing
|
||||||
while num > 0 {
|
while num > 0 {
|
||||||
// Get records batch
|
// Get records batch
|
||||||
|
@ -903,7 +903,7 @@ impl Transaction {
|
||||||
if n == i + 1 {
|
if n == i + 1 {
|
||||||
nxt = Some(k.clone());
|
nxt = Some(k.clone());
|
||||||
}
|
}
|
||||||
out.push(Hb::decode(k.as_slice())?);
|
out.push(crate::key::root::hb::Hb::decode(k.as_slice())?);
|
||||||
// Count
|
// Count
|
||||||
num -= 1;
|
num -= 1;
|
||||||
}
|
}
|
||||||
|
@ -913,8 +913,8 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn scan_cl(&mut self, limit: u32) -> Result<Vec<ClusterMembership>, Error> {
|
pub async fn scan_cl(&mut self, limit: u32) -> Result<Vec<ClusterMembership>, Error> {
|
||||||
let beg = crate::key::cl::Cl::prefix();
|
let beg = crate::key::root::nd::Nd::prefix();
|
||||||
let end = crate::key::cl::Cl::suffix();
|
let end = crate::key::root::nd::Nd::suffix();
|
||||||
trace!("Scan start: {} ({:?})", String::from_utf8_lossy(&beg).to_string(), &beg);
|
trace!("Scan start: {} ({:?})", String::from_utf8_lossy(&beg).to_string(), &beg);
|
||||||
trace!("Scan end: {} ({:?})", String::from_utf8_lossy(&end).to_string(), &end);
|
trace!("Scan end: {} ({:?})", String::from_utf8_lossy(&end).to_string(), &end);
|
||||||
let mut nxt: Option<Key> = None;
|
let mut nxt: Option<Key> = None;
|
||||||
|
@ -959,7 +959,11 @@ impl Transaction {
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delr_hb(&mut self, ts: Vec<Hb>, limit: u32) -> Result<(), Error> {
|
pub async fn delr_hb(
|
||||||
|
&mut self,
|
||||||
|
ts: Vec<crate::key::root::hb::Hb>,
|
||||||
|
limit: u32,
|
||||||
|
) -> Result<(), Error> {
|
||||||
trace!("delr_hb: ts={:?} limit={:?}", ts, limit);
|
trace!("delr_hb: ts={:?} limit={:?}", ts, limit);
|
||||||
for hb in ts.into_iter() {
|
for hb in ts.into_iter() {
|
||||||
self.del(hb).await?;
|
self.del(hb).await?;
|
||||||
|
@ -969,18 +973,14 @@ impl Transaction {
|
||||||
|
|
||||||
pub async fn del_lv(&mut self, ns: &str, db: &str, tb: &str, lv: Uuid) -> Result<(), Error> {
|
pub async fn del_lv(&mut self, ns: &str, db: &str, tb: &str, lv: Uuid) -> Result<(), Error> {
|
||||||
trace!("del_lv: ns={:?} db={:?} tb={:?} lv={:?}", ns, db, tb, lv);
|
trace!("del_lv: ns={:?} db={:?} tb={:?} lv={:?}", ns, db, tb, lv);
|
||||||
let key = crate::key::lv::new(ns, db, tb, lv);
|
let key = crate::key::table::lq::new(ns, db, tb, lv);
|
||||||
self.cache.del(&key.clone().into());
|
self.cache.del(&key.clone().into());
|
||||||
self.del(key).await
|
self.del(key).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn scan_lq<'a>(
|
pub async fn scan_lq<'a>(&mut self, node: &Uuid, limit: u32) -> Result<Vec<LqValue>, Error> {
|
||||||
&mut self,
|
let pref = crate::key::node::lq::prefix_nd(node);
|
||||||
node: &uuid::Uuid,
|
let suff = crate::key::node::lq::suffix_nd(node);
|
||||||
limit: u32,
|
|
||||||
) -> Result<Vec<LqValue>, Error> {
|
|
||||||
let pref = lq::prefix_nd(node);
|
|
||||||
let suff = lq::suffix_nd(node);
|
|
||||||
trace!(
|
trace!(
|
||||||
"Scanning range from pref={}, suff={}",
|
"Scanning range from pref={}, suff={}",
|
||||||
crate::key::debug::sprint_key(&pref),
|
crate::key::debug::sprint_key(&pref),
|
||||||
|
@ -991,10 +991,10 @@ impl Transaction {
|
||||||
let mut res: Vec<LqValue> = vec![];
|
let mut res: Vec<LqValue> = vec![];
|
||||||
for (key, value) in scanned {
|
for (key, value) in scanned {
|
||||||
trace!("scan_lq: key={:?} value={:?}", &key, &value);
|
trace!("scan_lq: key={:?} value={:?}", &key, &value);
|
||||||
let lq = Lq::decode(key.as_slice())?;
|
let lq = crate::key::node::lq::Lq::decode(key.as_slice())?;
|
||||||
let tb: String = String::from_utf8(value).unwrap();
|
let tb: String = String::from_utf8(value).unwrap();
|
||||||
res.push(LqValue {
|
res.push(LqValue {
|
||||||
cl: lq.nd,
|
nd: lq.nd,
|
||||||
ns: lq.ns.to_string(),
|
ns: lq.ns.to_string(),
|
||||||
db: lq.db.to_string(),
|
db: lq.db.to_string(),
|
||||||
tb,
|
tb,
|
||||||
|
@ -1012,15 +1012,15 @@ impl Transaction {
|
||||||
live_stm: LiveStatement,
|
live_stm: LiveStatement,
|
||||||
expected: Option<LiveStatement>,
|
expected: Option<LiveStatement>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let key = crate::key::lv::new(ns, db, tb, live_stm.id.0);
|
let key = crate::key::table::lq::new(ns, db, tb, live_stm.id.0);
|
||||||
let key_enc = Lv::encode(&key)?;
|
let key_enc = crate::key::table::lq::Lq::encode(&key)?;
|
||||||
trace!("putc_lv ({:?}): key={:?}", &live_stm.id, crate::key::debug::sprint_key(&key_enc));
|
trace!("putc_lv ({:?}): key={:?}", &live_stm.id, crate::key::debug::sprint_key(&key_enc));
|
||||||
self.putc(key_enc, live_stm, expected).await
|
self.putc(key_enc, live_stm, expected).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve all namespace definitions in a datastore.
|
/// Retrieve all namespace definitions in a datastore.
|
||||||
pub async fn all_ns(&mut self) -> Result<Arc<[DefineNamespaceStatement]>, Error> {
|
pub async fn all_ns(&mut self) -> Result<Arc<[DefineNamespaceStatement]>, Error> {
|
||||||
let key = crate::key::ns::prefix();
|
let key = crate::key::root::ns::prefix();
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Nss(v) = e {
|
if let Entry::Nss(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1028,8 +1028,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::ns::prefix();
|
let beg = crate::key::root::ns::prefix();
|
||||||
let end = crate::key::ns::suffix();
|
let end = crate::key::root::ns::suffix();
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Nss(Arc::clone(&val)));
|
self.cache.set(key, Entry::Nss(Arc::clone(&val)));
|
||||||
|
@ -1039,7 +1039,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve all namespace login definitions for a specific namespace.
|
/// Retrieve all namespace login definitions for a specific namespace.
|
||||||
pub async fn all_nl(&mut self, ns: &str) -> Result<Arc<[DefineLoginStatement]>, Error> {
|
pub async fn all_nl(&mut self, ns: &str) -> Result<Arc<[DefineLoginStatement]>, Error> {
|
||||||
let key = crate::key::nl::prefix(ns);
|
let key = crate::key::namespace::lg::prefix(ns);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Nls(v) = e {
|
if let Entry::Nls(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1047,8 +1047,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::nl::prefix(ns);
|
let beg = crate::key::namespace::lg::prefix(ns);
|
||||||
let end = crate::key::nl::suffix(ns);
|
let end = crate::key::namespace::lg::suffix(ns);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Nls(Arc::clone(&val)));
|
self.cache.set(key, Entry::Nls(Arc::clone(&val)));
|
||||||
|
@ -1058,7 +1058,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve all namespace token definitions for a specific namespace.
|
/// Retrieve all namespace token definitions for a specific namespace.
|
||||||
pub async fn all_nt(&mut self, ns: &str) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
pub async fn all_nt(&mut self, ns: &str) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
||||||
let key = crate::key::nt::prefix(ns);
|
let key = crate::key::namespace::tk::prefix(ns);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Nts(v) = e {
|
if let Entry::Nts(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1066,8 +1066,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::nt::prefix(ns);
|
let beg = crate::key::namespace::tk::prefix(ns);
|
||||||
let end = crate::key::nt::suffix(ns);
|
let end = crate::key::namespace::tk::suffix(ns);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Nts(Arc::clone(&val)));
|
self.cache.set(key, Entry::Nts(Arc::clone(&val)));
|
||||||
|
@ -1077,7 +1077,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve all database definitions for a specific namespace.
|
/// Retrieve all database definitions for a specific namespace.
|
||||||
pub async fn all_db(&mut self, ns: &str) -> Result<Arc<[DefineDatabaseStatement]>, Error> {
|
pub async fn all_db(&mut self, ns: &str) -> Result<Arc<[DefineDatabaseStatement]>, Error> {
|
||||||
let key = crate::key::db::prefix(ns);
|
let key = crate::key::namespace::db::prefix(ns);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Dbs(v) = e {
|
if let Entry::Dbs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1085,8 +1085,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::db::prefix(ns);
|
let beg = crate::key::namespace::db::prefix(ns);
|
||||||
let end = crate::key::db::suffix(ns);
|
let end = crate::key::namespace::db::suffix(ns);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Dbs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Dbs(Arc::clone(&val)));
|
||||||
|
@ -1100,7 +1100,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineLoginStatement]>, Error> {
|
) -> Result<Arc<[DefineLoginStatement]>, Error> {
|
||||||
let key = crate::key::dl::prefix(ns, db);
|
let key = crate::key::database::lg::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Dls(v) = e {
|
if let Entry::Dls(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1108,8 +1108,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::dl::prefix(ns, db);
|
let beg = crate::key::database::lg::prefix(ns, db);
|
||||||
let end = crate::key::dl::suffix(ns, db);
|
let end = crate::key::database::lg::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Dls(Arc::clone(&val)));
|
self.cache.set(key, Entry::Dls(Arc::clone(&val)));
|
||||||
|
@ -1123,7 +1123,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
||||||
let key = crate::key::dt::prefix(ns, db);
|
let key = crate::key::database::tk::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Dts(v) = e {
|
if let Entry::Dts(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1131,8 +1131,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::dt::prefix(ns, db);
|
let beg = crate::key::database::tk::prefix(ns, db);
|
||||||
let end = crate::key::dt::suffix(ns, db);
|
let end = crate::key::database::tk::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Dts(Arc::clone(&val)));
|
self.cache.set(key, Entry::Dts(Arc::clone(&val)));
|
||||||
|
@ -1146,7 +1146,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineFunctionStatement]>, Error> {
|
) -> Result<Arc<[DefineFunctionStatement]>, Error> {
|
||||||
let key = crate::key::fc::prefix(ns, db);
|
let key = crate::key::database::fc::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Fcs(v) = e {
|
if let Entry::Fcs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1154,8 +1154,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::fc::prefix(ns, db);
|
let beg = crate::key::database::fc::prefix(ns, db);
|
||||||
let end = crate::key::fc::suffix(ns, db);
|
let end = crate::key::database::fc::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Fcs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Fcs(Arc::clone(&val)));
|
||||||
|
@ -1169,7 +1169,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineScopeStatement]>, Error> {
|
) -> Result<Arc<[DefineScopeStatement]>, Error> {
|
||||||
let key = crate::key::sc::prefix(ns, db);
|
let key = crate::key::database::sc::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Scs(v) = e {
|
if let Entry::Scs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1177,8 +1177,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::sc::prefix(ns, db);
|
let beg = crate::key::database::sc::prefix(ns, db);
|
||||||
let end = crate::key::sc::suffix(ns, db);
|
let end = crate::key::database::sc::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Scs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Scs(Arc::clone(&val)));
|
||||||
|
@ -1193,7 +1193,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
sc: &str,
|
sc: &str,
|
||||||
) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
) -> Result<Arc<[DefineTokenStatement]>, Error> {
|
||||||
let key = crate::key::st::prefix(ns, db, sc);
|
let key = crate::key::scope::tk::prefix(ns, db, sc);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Sts(v) = e {
|
if let Entry::Sts(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1201,8 +1201,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::st::prefix(ns, db, sc);
|
let beg = crate::key::scope::tk::prefix(ns, db, sc);
|
||||||
let end = crate::key::st::suffix(ns, db, sc);
|
let end = crate::key::scope::tk::suffix(ns, db, sc);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Sts(Arc::clone(&val)));
|
self.cache.set(key, Entry::Sts(Arc::clone(&val)));
|
||||||
|
@ -1216,7 +1216,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineParamStatement]>, Error> {
|
) -> Result<Arc<[DefineParamStatement]>, Error> {
|
||||||
let key = crate::key::pa::prefix(ns, db);
|
let key = crate::key::database::pa::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Pas(v) = e {
|
if let Entry::Pas(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1224,8 +1224,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::pa::prefix(ns, db);
|
let beg = crate::key::database::pa::prefix(ns, db);
|
||||||
let end = crate::key::pa::suffix(ns, db);
|
let end = crate::key::database::pa::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Pas(Arc::clone(&val)));
|
self.cache.set(key, Entry::Pas(Arc::clone(&val)));
|
||||||
|
@ -1239,7 +1239,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineTableStatement]>, Error> {
|
) -> Result<Arc<[DefineTableStatement]>, Error> {
|
||||||
let key = crate::key::tb::prefix(ns, db);
|
let key = crate::key::database::tb::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Tbs(v) = e {
|
if let Entry::Tbs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1247,8 +1247,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::tb::prefix(ns, db);
|
let beg = crate::key::database::tb::prefix(ns, db);
|
||||||
let end = crate::key::tb::suffix(ns, db);
|
let end = crate::key::database::tb::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Tbs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Tbs(Arc::clone(&val)));
|
||||||
|
@ -1263,7 +1263,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<[DefineEventStatement]>, Error> {
|
) -> Result<Arc<[DefineEventStatement]>, Error> {
|
||||||
let key = crate::key::ev::prefix(ns, db, tb);
|
let key = crate::key::table::ev::prefix(ns, db, tb);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Evs(v) = e {
|
if let Entry::Evs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1271,8 +1271,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::ev::prefix(ns, db, tb);
|
let beg = crate::key::table::ev::prefix(ns, db, tb);
|
||||||
let end = crate::key::ev::suffix(ns, db, tb);
|
let end = crate::key::table::ev::suffix(ns, db, tb);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Evs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Evs(Arc::clone(&val)));
|
||||||
|
@ -1287,7 +1287,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<[DefineFieldStatement]>, Error> {
|
) -> Result<Arc<[DefineFieldStatement]>, Error> {
|
||||||
let key = crate::key::fd::prefix(ns, db, tb);
|
let key = crate::key::table::fd::prefix(ns, db, tb);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Fds(v) = e {
|
if let Entry::Fds(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1295,8 +1295,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::fd::prefix(ns, db, tb);
|
let beg = crate::key::table::fd::prefix(ns, db, tb);
|
||||||
let end = crate::key::fd::suffix(ns, db, tb);
|
let end = crate::key::table::fd::suffix(ns, db, tb);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Fds(Arc::clone(&val)));
|
self.cache.set(key, Entry::Fds(Arc::clone(&val)));
|
||||||
|
@ -1311,7 +1311,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<[DefineIndexStatement]>, Error> {
|
) -> Result<Arc<[DefineIndexStatement]>, Error> {
|
||||||
let key = crate::key::ix::prefix(ns, db, tb);
|
let key = crate::key::table::ix::prefix(ns, db, tb);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Ixs(v) = e {
|
if let Entry::Ixs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1319,8 +1319,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::ix::prefix(ns, db, tb);
|
let beg = crate::key::table::ix::prefix(ns, db, tb);
|
||||||
let end = crate::key::ix::suffix(ns, db, tb);
|
let end = crate::key::table::ix::suffix(ns, db, tb);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Ixs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Ixs(Arc::clone(&val)));
|
||||||
|
@ -1335,7 +1335,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<[DefineTableStatement]>, Error> {
|
) -> Result<Arc<[DefineTableStatement]>, Error> {
|
||||||
let key = crate::key::ft::prefix(ns, db, tb);
|
let key = crate::key::table::ft::prefix(ns, db, tb);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Fts(v) = e {
|
if let Entry::Fts(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1343,8 +1343,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::ft::prefix(ns, db, tb);
|
let beg = crate::key::table::ft::prefix(ns, db, tb);
|
||||||
let end = crate::key::ft::suffix(ns, db, tb);
|
let end = crate::key::table::ft::suffix(ns, db, tb);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Fts(Arc::clone(&val)));
|
self.cache.set(key, Entry::Fts(Arc::clone(&val)));
|
||||||
|
@ -1359,7 +1359,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<[LiveStatement]>, Error> {
|
) -> Result<Arc<[LiveStatement]>, Error> {
|
||||||
let key = crate::key::lv::prefix(ns, db, tb);
|
let key = crate::key::table::lq::prefix(ns, db, tb);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Lvs(v) = e {
|
if let Entry::Lvs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1367,8 +1367,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::lv::prefix(ns, db, tb);
|
let beg = crate::key::table::lq::prefix(ns, db, tb);
|
||||||
let end = crate::key::lv::suffix(ns, db, tb);
|
let end = crate::key::table::lq::suffix(ns, db, tb);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Lvs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Lvs(Arc::clone(&val)));
|
||||||
|
@ -1377,18 +1377,18 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn all_lq(&mut self, nd: &uuid::Uuid) -> Result<Vec<LqValue>, Error> {
|
pub async fn all_lq(&mut self, nd: &uuid::Uuid) -> Result<Vec<LqValue>, Error> {
|
||||||
let beg = crate::key::lq::prefix_nd(nd);
|
let beg = crate::key::node::lq::prefix_nd(nd);
|
||||||
let end = crate::key::lq::suffix_nd(nd);
|
let end = crate::key::node::lq::suffix_nd(nd);
|
||||||
let lq_pairs = self.getr(beg..end, u32::MAX).await?;
|
let lq_pairs = self.getr(beg..end, u32::MAX).await?;
|
||||||
let mut lqs = vec![];
|
let mut lqs = vec![];
|
||||||
for (key, value) in lq_pairs {
|
for (key, value) in lq_pairs {
|
||||||
let lq_key = Lq::decode(key.as_slice())?;
|
let lq_key = crate::key::node::lq::Lq::decode(key.as_slice())?;
|
||||||
trace!("Value is {:?}", &value);
|
trace!("Value is {:?}", &value);
|
||||||
let lq_value = String::from_utf8(value).map_err(|e| {
|
let lq_value = String::from_utf8(value).map_err(|e| {
|
||||||
Error::Internal(format!("Failed to decode a value while reading LQ: {}", e))
|
Error::Internal(format!("Failed to decode a value while reading LQ: {}", e))
|
||||||
})?;
|
})?;
|
||||||
let lqv = LqValue {
|
let lqv = LqValue {
|
||||||
cl: *nd,
|
nd: *nd,
|
||||||
ns: lq_key.ns.to_string(),
|
ns: lq_key.ns.to_string(),
|
||||||
db: lq_key.db.to_string(),
|
db: lq_key.db.to_string(),
|
||||||
tb: lq_value,
|
tb: lq_value,
|
||||||
|
@ -1405,7 +1405,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<[DefineAnalyzerStatement]>, Error> {
|
) -> Result<Arc<[DefineAnalyzerStatement]>, Error> {
|
||||||
let key = crate::key::az::prefix(ns, db);
|
let key = crate::key::database::az::prefix(ns, db);
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Azs(v) = e {
|
if let Entry::Azs(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1413,8 +1413,8 @@ impl Transaction {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let beg = crate::key::az::prefix(ns, db);
|
let beg = crate::key::database::az::prefix(ns, db);
|
||||||
let end = crate::key::az::suffix(ns, db);
|
let end = crate::key::database::az::suffix(ns, db);
|
||||||
let val = self.getr(beg..end, u32::MAX).await?;
|
let val = self.getr(beg..end, u32::MAX).await?;
|
||||||
let val = val.convert().into();
|
let val = val.convert().into();
|
||||||
self.cache.set(key, Entry::Azs(Arc::clone(&val)));
|
self.cache.set(key, Entry::Azs(Arc::clone(&val)));
|
||||||
|
@ -1424,7 +1424,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve a specific namespace definition.
|
/// Retrieve a specific namespace definition.
|
||||||
pub async fn get_ns(&mut self, ns: &str) -> Result<DefineNamespaceStatement, Error> {
|
pub async fn get_ns(&mut self, ns: &str) -> Result<DefineNamespaceStatement, Error> {
|
||||||
let key = crate::key::ns::new(ns);
|
let key = crate::key::root::ns::new(ns);
|
||||||
let val = self.get(key).await?.ok_or(Error::NsNotFound {
|
let val = self.get(key).await?.ok_or(Error::NsNotFound {
|
||||||
value: ns.to_owned(),
|
value: ns.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1433,7 +1433,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve a specific namespace login definition.
|
/// Retrieve a specific namespace login definition.
|
||||||
pub async fn get_nl(&mut self, ns: &str, nl: &str) -> Result<DefineLoginStatement, Error> {
|
pub async fn get_nl(&mut self, ns: &str, nl: &str) -> Result<DefineLoginStatement, Error> {
|
||||||
let key = crate::key::nl::new(ns, nl);
|
let key = crate::key::namespace::lg::new(ns, nl);
|
||||||
let val = self.get(key).await?.ok_or(Error::NlNotFound {
|
let val = self.get(key).await?.ok_or(Error::NlNotFound {
|
||||||
value: nl.to_owned(),
|
value: nl.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1442,7 +1442,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve a specific namespace token definition.
|
/// Retrieve a specific namespace token definition.
|
||||||
pub async fn get_nt(&mut self, ns: &str, nt: &str) -> Result<DefineTokenStatement, Error> {
|
pub async fn get_nt(&mut self, ns: &str, nt: &str) -> Result<DefineTokenStatement, Error> {
|
||||||
let key = crate::key::nt::new(ns, nt);
|
let key = crate::key::namespace::tk::new(ns, nt);
|
||||||
let val = self.get(key).await?.ok_or(Error::NtNotFound {
|
let val = self.get(key).await?.ok_or(Error::NtNotFound {
|
||||||
value: nt.to_owned(),
|
value: nt.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1451,7 +1451,7 @@ impl Transaction {
|
||||||
|
|
||||||
/// Retrieve a specific database definition.
|
/// Retrieve a specific database definition.
|
||||||
pub async fn get_db(&mut self, ns: &str, db: &str) -> Result<DefineDatabaseStatement, Error> {
|
pub async fn get_db(&mut self, ns: &str, db: &str) -> Result<DefineDatabaseStatement, Error> {
|
||||||
let key = crate::key::db::new(ns, db);
|
let key = crate::key::namespace::db::new(ns, db);
|
||||||
let val = self.get(key).await?.ok_or(Error::DbNotFound {
|
let val = self.get(key).await?.ok_or(Error::DbNotFound {
|
||||||
value: db.to_owned(),
|
value: db.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1465,7 +1465,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
dl: &str,
|
dl: &str,
|
||||||
) -> Result<DefineLoginStatement, Error> {
|
) -> Result<DefineLoginStatement, Error> {
|
||||||
let key = crate::key::dl::new(ns, db, dl);
|
let key = crate::key::database::lg::new(ns, db, dl);
|
||||||
let val = self.get(key).await?.ok_or(Error::DlNotFound {
|
let val = self.get(key).await?.ok_or(Error::DlNotFound {
|
||||||
value: dl.to_owned(),
|
value: dl.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1479,7 +1479,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
dt: &str,
|
dt: &str,
|
||||||
) -> Result<DefineTokenStatement, Error> {
|
) -> Result<DefineTokenStatement, Error> {
|
||||||
let key = crate::key::dt::new(ns, db, dt);
|
let key = crate::key::database::tk::new(ns, db, dt);
|
||||||
let val = self.get(key).await?.ok_or(Error::DtNotFound {
|
let val = self.get(key).await?.ok_or(Error::DtNotFound {
|
||||||
value: dt.to_owned(),
|
value: dt.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1493,7 +1493,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
sc: &str,
|
sc: &str,
|
||||||
) -> Result<DefineScopeStatement, Error> {
|
) -> Result<DefineScopeStatement, Error> {
|
||||||
let key = crate::key::sc::new(ns, db, sc);
|
let key = crate::key::database::sc::new(ns, db, sc);
|
||||||
let val = self.get(key).await?.ok_or(Error::ScNotFound {
|
let val = self.get(key).await?.ok_or(Error::ScNotFound {
|
||||||
value: sc.to_owned(),
|
value: sc.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1508,7 +1508,7 @@ impl Transaction {
|
||||||
sc: &str,
|
sc: &str,
|
||||||
st: &str,
|
st: &str,
|
||||||
) -> Result<DefineTokenStatement, Error> {
|
) -> Result<DefineTokenStatement, Error> {
|
||||||
let key = crate::key::st::new(ns, db, sc, st);
|
let key = crate::key::scope::tk::new(ns, db, sc, st);
|
||||||
let val = self.get(key).await?.ok_or(Error::StNotFound {
|
let val = self.get(key).await?.ok_or(Error::StNotFound {
|
||||||
value: st.to_owned(),
|
value: st.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1522,7 +1522,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
fc: &str,
|
fc: &str,
|
||||||
) -> Result<DefineFunctionStatement, Error> {
|
) -> Result<DefineFunctionStatement, Error> {
|
||||||
let key = crate::key::fc::new(ns, db, fc);
|
let key = crate::key::database::fc::new(ns, db, fc);
|
||||||
let val = self.get(key).await?.ok_or(Error::FcNotFound {
|
let val = self.get(key).await?.ok_or(Error::FcNotFound {
|
||||||
value: fc.to_owned(),
|
value: fc.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1537,7 +1537,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
lq: Uuid,
|
lq: Uuid,
|
||||||
) -> Result<Strand, Error> {
|
) -> Result<Strand, Error> {
|
||||||
let key = lq::new(nd, ns, db, lq);
|
let key = crate::key::node::lq::new(nd, ns, db, lq);
|
||||||
let val = self.get(key).await?.ok_or(Error::LqNotFound {
|
let val = self.get(key).await?.ok_or(Error::LqNotFound {
|
||||||
value: lq.to_string(),
|
value: lq.to_string(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1551,8 +1551,8 @@ impl Transaction {
|
||||||
tb: &str,
|
tb: &str,
|
||||||
lv: &Uuid,
|
lv: &Uuid,
|
||||||
) -> Result<LiveStatement, Error> {
|
) -> Result<LiveStatement, Error> {
|
||||||
let key = crate::key::lv::new(ns, db, tb, *lv);
|
let key = crate::key::table::lq::new(ns, db, tb, *lv);
|
||||||
let key_enc = Lv::encode(&key)?;
|
let key_enc = crate::key::table::lq::Lq::encode(&key)?;
|
||||||
trace!("Getting lv ({:?}) {:?}", lv, crate::key::debug::sprint_key(&key_enc));
|
trace!("Getting lv ({:?}) {:?}", lv, crate::key::debug::sprint_key(&key_enc));
|
||||||
let val = self.get(key_enc).await?.ok_or(Error::LvNotFound {
|
let val = self.get(key_enc).await?.ok_or(Error::LvNotFound {
|
||||||
value: lv.to_string(),
|
value: lv.to_string(),
|
||||||
|
@ -1567,7 +1567,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
pa: &str,
|
pa: &str,
|
||||||
) -> Result<DefineParamStatement, Error> {
|
) -> Result<DefineParamStatement, Error> {
|
||||||
let key = crate::key::pa::new(ns, db, pa);
|
let key = crate::key::database::pa::new(ns, db, pa);
|
||||||
let val = self.get(key).await?.ok_or(Error::PaNotFound {
|
let val = self.get(key).await?.ok_or(Error::PaNotFound {
|
||||||
value: pa.to_owned(),
|
value: pa.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1581,7 +1581,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<DefineTableStatement, Error> {
|
) -> Result<DefineTableStatement, Error> {
|
||||||
let key = crate::key::tb::new(ns, db, tb);
|
let key = crate::key::database::tb::new(ns, db, tb);
|
||||||
let val = self.get(key).await?.ok_or(Error::TbNotFound {
|
let val = self.get(key).await?.ok_or(Error::TbNotFound {
|
||||||
value: tb.to_owned(),
|
value: tb.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1594,7 +1594,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
az: &str,
|
az: &str,
|
||||||
) -> Result<DefineAnalyzerStatement, Error> {
|
) -> Result<DefineAnalyzerStatement, Error> {
|
||||||
let key = crate::key::az::new(ns, db, az);
|
let key = crate::key::database::az::new(ns, db, az);
|
||||||
let val = self.get(key).await?.ok_or(Error::AzNotFound {
|
let val = self.get(key).await?.ok_or(Error::AzNotFound {
|
||||||
value: az.to_owned(),
|
value: az.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1608,7 +1608,7 @@ impl Transaction {
|
||||||
tb: &str,
|
tb: &str,
|
||||||
ix: &str,
|
ix: &str,
|
||||||
) -> Result<DefineIndexStatement, Error> {
|
) -> Result<DefineIndexStatement, Error> {
|
||||||
let key = crate::key::ix::new(ns, db, tb, ix);
|
let key = crate::key::table::ix::new(ns, db, tb, ix);
|
||||||
let val = self.get(key).await?.ok_or(Error::IxNotFound {
|
let val = self.get(key).await?.ok_or(Error::IxNotFound {
|
||||||
value: ix.to_owned(),
|
value: ix.to_owned(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -1625,7 +1625,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::ns::new(ns);
|
let key = crate::key::root::ns::new(ns);
|
||||||
let val = DefineNamespaceStatement {
|
let val = DefineNamespaceStatement {
|
||||||
name: ns.to_owned().into(),
|
name: ns.to_owned().into(),
|
||||||
};
|
};
|
||||||
|
@ -1653,7 +1653,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::db::new(ns, db);
|
let key = crate::key::namespace::db::new(ns, db);
|
||||||
let val = DefineDatabaseStatement {
|
let val = DefineDatabaseStatement {
|
||||||
name: db.to_owned().into(),
|
name: db.to_owned().into(),
|
||||||
changefeed: None,
|
changefeed: None,
|
||||||
|
@ -1683,7 +1683,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::sc::new(ns, db, sc);
|
let key = crate::key::database::sc::new(ns, db, sc);
|
||||||
let val = DefineScopeStatement {
|
let val = DefineScopeStatement {
|
||||||
name: sc.to_owned().into(),
|
name: sc.to_owned().into(),
|
||||||
..DefineScopeStatement::default()
|
..DefineScopeStatement::default()
|
||||||
|
@ -1713,7 +1713,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::tb::new(ns, db, tb);
|
let key = crate::key::database::tb::new(ns, db, tb);
|
||||||
let val = DefineTableStatement {
|
let val = DefineTableStatement {
|
||||||
name: tb.to_owned().into(),
|
name: tb.to_owned().into(),
|
||||||
permissions: Permissions::none(),
|
permissions: Permissions::none(),
|
||||||
|
@ -1736,7 +1736,7 @@ impl Transaction {
|
||||||
&mut self,
|
&mut self,
|
||||||
ns: &str,
|
ns: &str,
|
||||||
) -> Result<Arc<DefineNamespaceStatement>, Error> {
|
) -> Result<Arc<DefineNamespaceStatement>, Error> {
|
||||||
let key = crate::key::ns::new(ns).encode()?;
|
let key = crate::key::root::ns::new(ns).encode()?;
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Ns(v) = e {
|
if let Entry::Ns(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1759,7 +1759,7 @@ impl Transaction {
|
||||||
ns: &str,
|
ns: &str,
|
||||||
db: &str,
|
db: &str,
|
||||||
) -> Result<Arc<DefineDatabaseStatement>, Error> {
|
) -> Result<Arc<DefineDatabaseStatement>, Error> {
|
||||||
let key = crate::key::db::new(ns, db).encode()?;
|
let key = crate::key::namespace::db::new(ns, db).encode()?;
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Db(v) = e {
|
if let Entry::Db(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1783,7 +1783,7 @@ impl Transaction {
|
||||||
db: &str,
|
db: &str,
|
||||||
tb: &str,
|
tb: &str,
|
||||||
) -> Result<Arc<DefineTableStatement>, Error> {
|
) -> Result<Arc<DefineTableStatement>, Error> {
|
||||||
let key = crate::key::tb::new(ns, db, tb).encode()?;
|
let key = crate::key::database::tb::new(ns, db, tb).encode()?;
|
||||||
Ok(if let Some(e) = self.cache.get(&key) {
|
Ok(if let Some(e) = self.cache.get(&key) {
|
||||||
if let Entry::Tb(v) = e {
|
if let Entry::Tb(v) = e {
|
||||||
v
|
v
|
||||||
|
@ -1811,7 +1811,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::ns::new(ns);
|
let key = crate::key::root::ns::new(ns);
|
||||||
let val = DefineNamespaceStatement {
|
let val = DefineNamespaceStatement {
|
||||||
name: ns.to_owned().into(),
|
name: ns.to_owned().into(),
|
||||||
};
|
};
|
||||||
|
@ -1839,7 +1839,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::db::new(ns, db);
|
let key = crate::key::namespace::db::new(ns, db);
|
||||||
let val = DefineDatabaseStatement {
|
let val = DefineDatabaseStatement {
|
||||||
name: db.to_owned().into(),
|
name: db.to_owned().into(),
|
||||||
changefeed: None,
|
changefeed: None,
|
||||||
|
@ -1869,7 +1869,7 @@ impl Transaction {
|
||||||
value,
|
value,
|
||||||
}) => match strict {
|
}) => match strict {
|
||||||
false => {
|
false => {
|
||||||
let key = crate::key::tb::new(ns, db, tb);
|
let key = crate::key::database::tb::new(ns, db, tb);
|
||||||
let val = DefineTableStatement {
|
let val = DefineTableStatement {
|
||||||
name: tb.to_owned().into(),
|
name: tb.to_owned().into(),
|
||||||
permissions: Permissions::none(),
|
permissions: Permissions::none(),
|
||||||
|
@ -2072,8 +2072,8 @@ impl Transaction {
|
||||||
chn.send(bytes!("-- ------------------------------")).await?;
|
chn.send(bytes!("-- ------------------------------")).await?;
|
||||||
chn.send(bytes!("")).await?;
|
chn.send(bytes!("")).await?;
|
||||||
// Fetch records
|
// Fetch records
|
||||||
let beg = thing::prefix(ns, db, &tb.name);
|
let beg = crate::key::thing::prefix(ns, db, &tb.name);
|
||||||
let end = thing::suffix(ns, db, &tb.name);
|
let end = crate::key::thing::suffix(ns, db, &tb.name);
|
||||||
let mut nxt: Option<Vec<u8>> = None;
|
let mut nxt: Option<Vec<u8>> = None;
|
||||||
loop {
|
loop {
|
||||||
let res = match nxt {
|
let res = match nxt {
|
||||||
|
@ -2104,7 +2104,7 @@ impl Transaction {
|
||||||
}
|
}
|
||||||
// Parse the key and the value
|
// Parse the key and the value
|
||||||
let k: crate::key::thing::Thing = (&k).into();
|
let k: crate::key::thing::Thing = (&k).into();
|
||||||
let v: crate::sql::value::Value = (&v).into();
|
let v: Value = (&v).into();
|
||||||
let t = Thing::from((k.tb, k.id));
|
let t = Thing::from((k.tb, k.id));
|
||||||
// Check if this is a graph edge
|
// Check if this is a graph edge
|
||||||
match (v.pick(&*EDGE), v.pick(&*IN), v.pick(&*OUT)) {
|
match (v.pick(&*EDGE), v.pick(&*IN), v.pick(&*OUT)) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::sql::idiom::{Idiom, Idioms};
|
||||||
use crate::sql::index::Index;
|
use crate::sql::index::Index;
|
||||||
use crate::sql::kind::{kind, Kind};
|
use crate::sql::kind::{kind, Kind};
|
||||||
use crate::sql::permission::{permissions, Permissions};
|
use crate::sql::permission::{permissions, Permissions};
|
||||||
use crate::sql::statements::{RemoveIndexStatement, UpdateStatement};
|
use crate::sql::statements::UpdateStatement;
|
||||||
use crate::sql::strand::strand_raw;
|
use crate::sql::strand::strand_raw;
|
||||||
use crate::sql::tokenizer::{tokenizers, Tokenizer};
|
use crate::sql::tokenizer::{tokenizers, Tokenizer};
|
||||||
use crate::sql::value::{value, values, Value, Values};
|
use crate::sql::value::{value, values, Value, Values};
|
||||||
|
@ -145,7 +145,7 @@ impl DefineNamespaceStatement {
|
||||||
// Allowed to run?
|
// Allowed to run?
|
||||||
opt.check(Level::Kv)?;
|
opt.check(Level::Kv)?;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::ns::new(&self.name);
|
let key = crate::key::root::ns::new(&self.name);
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -200,7 +200,7 @@ impl DefineDatabaseStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::db::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::db::new(opt.ns(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
|
@ -281,7 +281,7 @@ impl DefineFunctionStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::fc::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::fc::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -363,7 +363,7 @@ impl DefineAnalyzerStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::az::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::az::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -439,7 +439,7 @@ impl DefineLoginStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::nl::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::lg::new(opt.ns(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
|
@ -453,7 +453,7 @@ impl DefineLoginStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::dl::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::lg::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -559,7 +559,7 @@ impl DefineTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::nt::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::tk::new(opt.ns(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
|
@ -573,7 +573,7 @@ impl DefineTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::dt::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::tk::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -588,7 +588,7 @@ impl DefineTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::st::new(opt.ns(), opt.db(), sc, &self.name);
|
let key = crate::key::scope::tk::new(opt.ns(), opt.db(), sc, &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.add_sc(opt.ns(), opt.db(), sc, opt.strict).await?;
|
run.add_sc(opt.ns(), opt.db(), sc, opt.strict).await?;
|
||||||
|
@ -672,7 +672,7 @@ impl DefineScopeStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::sc::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::sc::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -790,7 +790,7 @@ impl DefineParamStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::pa::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::pa::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
|
@ -854,22 +854,22 @@ impl DefineTableStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::tb::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::tb::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Check if table is a view
|
// Check if table is a view
|
||||||
if let Some(view) = &self.view {
|
if let Some(view) = &self.view {
|
||||||
// Remove the table data
|
// Remove the table data
|
||||||
let key = crate::key::table::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::table::all::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.delp(key, u32::MAX).await?;
|
run.delp(key, u32::MAX).await?;
|
||||||
// Process each foreign table
|
// Process each foreign table
|
||||||
for v in view.what.0.iter() {
|
for v in view.what.0.iter() {
|
||||||
// Save the view config
|
// Save the view config
|
||||||
let key = crate::key::ft::new(opt.ns(), opt.db(), v, &self.name);
|
let key = crate::key::table::ft::new(opt.ns(), opt.db(), v, &self.name);
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::ft::prefix(opt.ns(), opt.db(), v);
|
let key = crate::key::table::ft::prefix(opt.ns(), opt.db(), v);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
}
|
}
|
||||||
// Release the transaction
|
// Release the transaction
|
||||||
|
@ -1057,13 +1057,13 @@ impl DefineEventStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
|
let key = crate::key::table::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::ev::prefix(opt.ns(), opt.db(), &self.what);
|
let key = crate::key::table::ev::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -1142,13 +1142,13 @@ impl DefineFieldStatement {
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let fd = self.name.to_string();
|
let fd = self.name.to_string();
|
||||||
let key = crate::key::fd::new(opt.ns(), opt.db(), &self.what, &fd);
|
let key = crate::key::table::fd::new(opt.ns(), opt.db(), &self.what, &fd);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::fd::prefix(opt.ns(), opt.db(), &self.what);
|
let key = crate::key::table::fd::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -1301,16 +1301,17 @@ impl DefineIndexStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Process the statement
|
// Process the statement
|
||||||
let key = crate::key::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
|
let key = crate::key::table::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
run.add_ns(opt.ns(), opt.strict).await?;
|
run.add_ns(opt.ns(), opt.strict).await?;
|
||||||
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
run.add_db(opt.ns(), opt.db(), opt.strict).await?;
|
||||||
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?;
|
||||||
run.set(key, self).await?;
|
run.set(key, self).await?;
|
||||||
// Clear the cache
|
|
||||||
let key = crate::key::ix::prefix(opt.ns(), opt.db(), &self.what);
|
|
||||||
run.clr(key).await?;
|
|
||||||
// Remove the index data
|
// Remove the index data
|
||||||
RemoveIndexStatement::delete_resources(&mut run, opt, &self.what, &self.name).await?;
|
let key = crate::key::index::all::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
|
run.delp(key, u32::MAX).await?;
|
||||||
|
// Clear the cache
|
||||||
|
let key = crate::key::table::ix::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
|
run.clr(key).await?;
|
||||||
// Release the transaction
|
// Release the transaction
|
||||||
drop(run);
|
drop(run);
|
||||||
// Force queries to run
|
// Force queries to run
|
||||||
|
|
|
@ -35,16 +35,16 @@ impl KillStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Fetch the live query key
|
// Fetch the live query key
|
||||||
let key = crate::key::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
let key = crate::key::node::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
||||||
// Fetch the live query key if it exists
|
// Fetch the live query key if it exists
|
||||||
match run.get(key).await? {
|
match run.get(key).await? {
|
||||||
Some(val) => match std::str::from_utf8(&val) {
|
Some(val) => match std::str::from_utf8(&val) {
|
||||||
Ok(tb) => {
|
Ok(tb) => {
|
||||||
// Delete the node live query
|
// Delete the node live query
|
||||||
let key = crate::key::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
let key = crate::key::node::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Delete the table live query
|
// Delete the table live query
|
||||||
let key = crate::key::lv::new(opt.ns(), opt.db(), tb, self.id.0);
|
let key = crate::key::table::lq::new(opt.ns(), opt.db(), tb, self.id.0);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -64,10 +64,10 @@ impl LiveStatement {
|
||||||
}
|
}
|
||||||
stm.node = opt.id()?;
|
stm.node = opt.id()?;
|
||||||
// Insert the node live query
|
// Insert the node live query
|
||||||
let key = crate::key::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
let key = crate::key::node::lq::new(opt.id()?, opt.ns(), opt.db(), self.id.0);
|
||||||
run.putc(key, tb.as_str(), None).await?;
|
run.putc(key, tb.as_str(), None).await?;
|
||||||
// Insert the table live query
|
// Insert the table live query
|
||||||
let key = crate::key::lv::new(opt.ns(), opt.db(), &tb, self.id.0);
|
let key = crate::key::table::lq::new(opt.ns(), opt.db(), &tb, self.id.0);
|
||||||
run.putc(key, stm, None).await?;
|
run.putc(key, stm, None).await?;
|
||||||
}
|
}
|
||||||
v => {
|
v => {
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::dbs::Options;
|
||||||
use crate::dbs::{Level, Transaction};
|
use crate::dbs::{Level, Transaction};
|
||||||
use crate::doc::CursorDoc;
|
use crate::doc::CursorDoc;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::kvs;
|
|
||||||
use crate::sql::base::{base, base_or_scope, Base};
|
use crate::sql::base::{base, base_or_scope, Base};
|
||||||
use crate::sql::comment::{mightbespace, shouldbespace};
|
use crate::sql::comment::{mightbespace, shouldbespace};
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
|
@ -124,10 +123,10 @@ impl RemoveNamespaceStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::ns::new(&self.name);
|
let key = crate::key::root::ns::new(&self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Delete the resource data
|
// Delete the resource data
|
||||||
let key = crate::key::namespace::new(&self.name);
|
let key = crate::key::namespace::all::new(&self.name);
|
||||||
run.delp(key, u32::MAX).await?;
|
run.delp(key, u32::MAX).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -178,10 +177,10 @@ impl RemoveDatabaseStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::db::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::db::new(opt.ns(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Delete the resource data
|
// Delete the resource data
|
||||||
let key = crate::key::database::new(opt.ns(), &self.name);
|
let key = crate::key::database::all::new(opt.ns(), &self.name);
|
||||||
run.delp(key, u32::MAX).await?;
|
run.delp(key, u32::MAX).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -232,7 +231,7 @@ impl RemoveFunctionStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::fc::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::fc::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -290,7 +289,7 @@ impl RemoveAnalyzerStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::az::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::az::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// TODO Check that the analyzer is not used in any schema
|
// TODO Check that the analyzer is not used in any schema
|
||||||
// Ok all good
|
// Ok all good
|
||||||
|
@ -345,7 +344,7 @@ impl RemoveLoginStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::nl::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::lg::new(opt.ns(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -358,7 +357,7 @@ impl RemoveLoginStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::dl::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::lg::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -420,7 +419,7 @@ impl RemoveTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::nt::new(opt.ns(), &self.name);
|
let key = crate::key::namespace::tk::new(opt.ns(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -433,7 +432,7 @@ impl RemoveTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::dt::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::tk::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -446,7 +445,7 @@ impl RemoveTokenStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::st::new(opt.ns(), opt.db(), sc, &self.name);
|
let key = crate::key::scope::tk::new(opt.ns(), opt.db(), sc, &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -505,10 +504,10 @@ impl RemoveScopeStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::sc::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::sc::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Remove the resource data
|
// Remove the resource data
|
||||||
let key = crate::key::scope::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::scope::all::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.delp(key, u32::MAX).await?;
|
run.delp(key, u32::MAX).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -559,7 +558,7 @@ impl RemoveParamStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::pa::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::pa::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -611,10 +610,10 @@ impl RemoveTableStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::tb::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::database::tb::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Remove the resource data
|
// Remove the resource data
|
||||||
let key = crate::key::table::new(opt.ns(), opt.db(), &self.name);
|
let key = crate::key::table::all::new(opt.ns(), opt.db(), &self.name);
|
||||||
run.delp(key, u32::MAX).await?;
|
run.delp(key, u32::MAX).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -666,10 +665,10 @@ impl RemoveEventStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
|
let key = crate::key::table::ev::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::ev::prefix(opt.ns(), opt.db(), &self.what);
|
let key = crate::key::table::ev::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -728,10 +727,10 @@ impl RemoveFieldStatement {
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let fd = self.name.to_string();
|
let fd = self.name.to_string();
|
||||||
let key = crate::key::fd::new(opt.ns(), opt.db(), &self.what, &fd);
|
let key = crate::key::table::fd::new(opt.ns(), opt.db(), &self.what, &fd);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::fd::prefix(opt.ns(), opt.db(), &self.what);
|
let key = crate::key::table::fd::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
|
@ -789,50 +788,17 @@ impl RemoveIndexStatement {
|
||||||
// Claim transaction
|
// Claim transaction
|
||||||
let mut run = txn.lock().await;
|
let mut run = txn.lock().await;
|
||||||
// Delete the definition
|
// Delete the definition
|
||||||
let key = crate::key::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
|
let key = crate::key::table::ix::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
run.del(key).await?;
|
run.del(key).await?;
|
||||||
|
// Remove the index data
|
||||||
|
let key = crate::key::index::all::new(opt.ns(), opt.db(), &self.what, &self.name);
|
||||||
|
run.delp(key, u32::MAX).await?;
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
let key = crate::key::ix::prefix(opt.ns(), opt.db(), &self.what);
|
let key = crate::key::table::ix::prefix(opt.ns(), opt.db(), &self.what);
|
||||||
run.clr(key).await?;
|
run.clr(key).await?;
|
||||||
// Delete resource
|
|
||||||
Self::delete_resources(&mut run, opt, &self.what, &self.name).await?;
|
|
||||||
// Ok all good
|
// Ok all good
|
||||||
Ok(Value::None)
|
Ok(Value::None)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the resource data (whatever the type of the index)
|
|
||||||
pub(crate) async fn delete_resources(
|
|
||||||
run: &mut kvs::Transaction,
|
|
||||||
opt: &Options,
|
|
||||||
tb: &str,
|
|
||||||
ix: &str,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let rng = crate::key::index::Index::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bc::Bc::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bd::Bd::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bf::Bf::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bi::Bi::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bk::Bk::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bl::Bl::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bo::Bo::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bp::Bp::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let key = crate::key::bs::Bs::new(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.del(key).await?;
|
|
||||||
let rng = crate::key::bt::Bt::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
let rng = crate::key::bu::Bu::range(opt.ns(), opt.db(), tb, ix);
|
|
||||||
run.delr(rng, u32::MAX).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for RemoveIndexStatement {
|
impl Display for RemoveIndexStatement {
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
mod parse;
|
mod parse;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod util;
|
||||||
|
|
||||||
use parse::Parse;
|
use parse::Parse;
|
||||||
use surrealdb::dbs::Session;
|
use surrealdb::dbs::Session;
|
||||||
use surrealdb::err::Error;
|
use surrealdb::err::Error;
|
||||||
use surrealdb::key::bc::Bc;
|
|
||||||
use surrealdb::key::bd::Bd;
|
|
||||||
use surrealdb::key::bf::Bf;
|
|
||||||
use surrealdb::key::bi::Bi;
|
|
||||||
use surrealdb::key::bk::Bk;
|
|
||||||
use surrealdb::key::bl::Bl;
|
|
||||||
use surrealdb::key::bo::Bo;
|
|
||||||
use surrealdb::key::bp::Bp;
|
|
||||||
use surrealdb::key::bs::Bs;
|
|
||||||
use surrealdb::key::bt::Bt;
|
|
||||||
use surrealdb::key::bu::Bu;
|
|
||||||
use surrealdb::key::index::Index;
|
|
||||||
use surrealdb::kvs::Datastore;
|
use surrealdb::kvs::Datastore;
|
||||||
use surrealdb::sql::Value;
|
use surrealdb::sql::Value;
|
||||||
|
|
||||||
|
@ -86,20 +77,6 @@ async fn remove_statement_analyzer() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! check_empty_range {
|
|
||||||
($tx:expr, $rng:expr) => {{
|
|
||||||
let r = $tx.getr($rng, 1).await?;
|
|
||||||
assert!(r.is_empty());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! check_none_val {
|
|
||||||
($tx:expr, $key:expr) => {{
|
|
||||||
let r = $tx.get($key).await?;
|
|
||||||
assert!(r.is_none());
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn remove_statement_index() -> Result<(), Error> {
|
async fn remove_statement_index() -> Result<(), Error> {
|
||||||
let sql = "
|
let sql = "
|
||||||
|
@ -135,18 +112,7 @@ async fn remove_statement_index() -> Result<(), Error> {
|
||||||
|
|
||||||
let mut tx = dbs.transaction(false, false).await?;
|
let mut tx = dbs.transaction(false, false).await?;
|
||||||
for ix in ["uniq_isbn", "idx_author", "ft_title"] {
|
for ix in ["uniq_isbn", "idx_author", "ft_title"] {
|
||||||
check_empty_range!(&mut tx, Bc::range("test", "test", "book", ix));
|
assert_empty_prefix!(&mut tx, surrealdb::key::index::all::new("test", "test", "book", ix));
|
||||||
check_empty_range!(&mut tx, Bd::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bf::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bi::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bk::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bl::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bo::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bp::range("test", "test", "book", ix));
|
|
||||||
check_none_val!(&mut tx, Bs::new("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bt::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Bu::range("test", "test", "book", ix));
|
|
||||||
check_empty_range!(&mut tx, Index::range("test", "test", "book", ix));
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
23
lib/tests/util.rs
Normal file
23
lib/tests/util.rs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! assert_empty_val {
|
||||||
|
($tx:expr, $key:expr) => {{
|
||||||
|
let r = $tx.get($key).await?;
|
||||||
|
assert!(r.is_none());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! assert_empty_prefix {
|
||||||
|
($tx:expr, $rng:expr) => {{
|
||||||
|
let r = $tx.getp($rng, 1).await?;
|
||||||
|
assert!(r.is_empty());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! assert_empty_range {
|
||||||
|
($tx:expr, $rng:expr) => {{
|
||||||
|
let r = $tx.getr($rng, 1).await?;
|
||||||
|
assert!(r.is_empty());
|
||||||
|
}};
|
||||||
|
}
|
Loading…
Reference in a new issue