Optimization - Zero copy key deserialization. (#1880)

This commit is contained in:
Finn Bear 2023-04-29 09:44:09 -07:00 committed by GitHub
parent 59947749e3
commit c295cb0509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 371 additions and 351 deletions

5
Cargo.lock generated
View file

@ -3710,11 +3710,12 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "storekey" name = "storekey"
version = "0.4.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "475592c1aa8849fa7874777c9df46aa93ffc47851c7c60bee88b1745a1adb893" checksum = "43c42833834a5d23b344f71d87114e0cc9994766a5c42938f4b50e7b2aef85b2"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"memchr",
"serde", "serde",
"thiserror", "thiserror",
] ]

View file

@ -92,7 +92,7 @@ serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96" serde_json = "1.0.96"
sha-1 = "0.10.1" sha-1 = "0.10.1"
sha2 = "0.10.6" sha2 = "0.10.6"
storekey = "0.4.1" storekey = "0.5.0"
thiserror = "1.0.40" thiserror = "1.0.40"
tikv = { version = "0.1.0", package = "tikv-client", optional = true } tikv = { version = "0.1.0", package = "tikv-client", optional = true }
tokio-util = { version = "0.7.7", optional = true, features = ["compat"] } tokio-util = { version = "0.7.7", optional = true, features = ["compat"] }

View file

@ -2,21 +2,21 @@ 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 { pub struct Database<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
} }
pub fn new(ns: &str, db: &str) -> Database { pub fn new<'a>(ns: &'a str, db: &'a str) -> Database<'a> {
Database::new(ns.to_string(), db.to_string()) Database::new(ns, db)
} }
impl Database { impl<'a> Database<'a> {
pub fn new(ns: String, db: String) -> Database { pub fn new(ns: &'a str, db: &'a str) -> Self {
Database { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -33,8 +33,8 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Database::new( let val = Database::new(
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Database::encode(&val).unwrap(); let enc = Database::encode(&val).unwrap();
let dec = Database::decode(&enc).unwrap(); let dec = Database::decode(&enc).unwrap();

View file

@ -2,18 +2,18 @@ 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 Db { pub struct Db<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
_c: u8, _c: u8,
_d: u8, _d: u8,
pub db: String, pub db: &'a str,
} }
pub fn new(ns: &str, db: &str) -> Db { pub fn new<'a>(ns: &'a str, db: &'a str) -> Db<'a> {
Db::new(ns.to_string(), db.to_string()) Db::new(ns, db)
} }
pub fn prefix(ns: &str) -> Vec<u8> { pub fn prefix(ns: &str) -> Vec<u8> {
@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec<u8> {
k k
} }
impl Db { impl<'a> Db<'a> {
pub fn new(ns: String, db: String) -> Db { pub fn new(ns: &'a str, db: &'a str) -> Self {
Db { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -49,8 +49,8 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Db::new( let val = Db::new(
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Db::encode(&val).unwrap(); let enc = Db::encode(&val).unwrap();
let dec = Db::decode(&enc).unwrap(); let dec = Db::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 { pub struct Dl<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub dl: String, pub dl: &'a str,
} }
pub fn new(ns: &str, db: &str, dl: &str) -> Dl { pub fn new<'a>(ns: &'a str, db: &'a str, dl: &'a str) -> Dl<'a> {
Dl::new(ns.to_string(), db.to_string(), dl.to_string()) Dl::new(ns, db, dl)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Dl { impl<'a> Dl<'a> {
pub fn new(ns: String, db: String, dl: String) -> Dl { pub fn new(ns: &'a str, db: &'a str, dl: &'a str) -> Self {
Dl { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Dl::new( let val = Dl::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Dl::encode(&val).unwrap(); let enc = Dl::encode(&val).unwrap();
let dec = Dl::decode(&enc).unwrap(); let dec = Dl::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 { pub struct Dt<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub tk: String, pub tk: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str) -> Dt { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Dt<'a> {
Dt::new(ns.to_string(), db.to_string(), tb.to_string()) Dt::new(ns, db, tb)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Dt { impl<'a> Dt<'a> {
pub fn new(ns: String, db: String, tk: String) -> Dt { pub fn new(ns: &'a str, db: &'a str, tk: &'a str) -> Self {
Dt { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Dt::new( let val = Dt::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Dt::encode(&val).unwrap(); let enc = Dt::encode(&val).unwrap();
let dec = Dt::decode(&enc).unwrap(); let dec = Dt::decode(&enc).unwrap();

View file

@ -2,22 +2,22 @@ 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 Ev { pub struct Ev<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub ev: String, pub ev: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str, ev: &str) -> Ev { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Ev<'a> {
Ev::new(ns.to_string(), db.to_string(), tb.to_string(), ev.to_string()) Ev::new(ns, db, tb, ev)
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Ev { impl<'a> Ev<'a> {
pub fn new(ns: String, db: String, tb: String, ev: String) -> Ev { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Self {
Ev { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -57,10 +57,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ev::new( let val = Ev::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Ev::encode(&val).unwrap(); let enc = Ev::encode(&val).unwrap();
let dec = Ev::decode(&enc).unwrap(); let dec = Ev::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 Fc { pub struct Fc<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub fc: String, pub fc: &'a str,
} }
pub fn new(ns: &str, db: &str, fc: &str) -> Fc { pub fn new<'a>(ns: &'a str, db: &'a str, fc: &'a str) -> Fc<'a> {
Fc::new(ns.to_string(), db.to_string(), fc.to_string()) Fc::new(ns, db, fc)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Fc { impl<'a> Fc<'a> {
pub fn new(ns: String, db: String, fc: String) -> Fc { pub fn new(ns: &'a str, db: &'a str, fc: &'a str) -> Self {
Fc { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Fc::new( let val = Fc::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Fc::encode(&val).unwrap(); let enc = Fc::encode(&val).unwrap();
let dec = Fc::decode(&enc).unwrap(); let dec = Fc::decode(&enc).unwrap();

View file

@ -2,22 +2,22 @@ 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 Fd { pub struct Fd<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub fd: String, pub fd: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str, fd: &str) -> Fd { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, fd: &'a str) -> Fd<'a> {
Fd::new(ns.to_string(), db.to_string(), tb.to_string(), fd.to_string()) Fd::new(ns, db, tb, fd)
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Fd { impl<'a> Fd<'a> {
pub fn new(ns: String, db: String, tb: String, fd: String) -> Fd { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, fd: &'a str) -> Self {
Fd { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -57,10 +57,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Fd::new( let val = Fd::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Fd::encode(&val).unwrap(); let enc = Fd::encode(&val).unwrap();
let dec = Fd::decode(&enc).unwrap(); let dec = Fd::decode(&enc).unwrap();

View file

@ -2,22 +2,22 @@ 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 Ft { pub struct Ft<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub ft: String, pub ft: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str, ft: &str) -> Ft { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ft: &'a str) -> Ft<'a> {
Ft::new(ns.to_string(), db.to_string(), tb.to_string(), ft.to_string()) Ft::new(ns, db, tb, ft)
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Ft { impl<'a> Ft<'a> {
pub fn new(ns: String, db: String, tb: String, ft: String) -> Ft { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ft: &'a str) -> Self {
Ft { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -57,10 +57,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ft::new( let val = Ft::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Ft::encode(&val).unwrap(); let enc = Ft::encode(&val).unwrap();
let dec = Ft::decode(&enc).unwrap(); let dec = Ft::decode(&enc).unwrap();

View file

@ -5,28 +5,28 @@ 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)]
struct Prefix { struct Prefix<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub id: Id, pub id: Id,
} }
impl Prefix { impl<'a> Prefix<'a> {
fn new(ns: &str, db: &str, tb: &str, id: &Id) -> Prefix { fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id) -> Self {
Prefix { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns: ns.to_string(), ns,
_b: 0x2a, // * _b: 0x2a, // *
db: db.to_string(), db,
_c: 0x2a, // * _c: 0x2a, // *
tb: tb.to_string(), tb,
_d: 0x7e, // ~ _d: 0x7e, // ~
id: id.to_owned(), id: id.to_owned(),
} }
@ -34,29 +34,29 @@ impl Prefix {
} }
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
struct PrefixEg { struct PrefixEg<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub id: Id, pub id: Id,
pub eg: Dir, pub eg: Dir,
} }
impl PrefixEg { impl<'a> PrefixEg<'a> {
fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir) -> PrefixEg { fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id, eg: &Dir) -> Self {
PrefixEg { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns: ns.to_string(), ns,
_b: 0x2a, // * _b: 0x2a, // *
db: db.to_string(), db,
_c: 0x2a, // * _c: 0x2a, // *
tb: tb.to_string(), tb,
_d: 0x7e, // ~ _d: 0x7e, // ~
id: id.to_owned(), id: id.to_owned(),
eg: eg.to_owned(), eg: eg.to_owned(),
@ -65,63 +65,63 @@ impl PrefixEg {
} }
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
struct PrefixFt { struct PrefixFt<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub id: Id, pub id: Id,
pub eg: Dir, pub eg: Dir,
pub ft: String, pub ft: &'a str,
} }
impl PrefixFt { impl<'a> PrefixFt<'a> {
fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, ft: &str) -> PrefixFt { fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id, eg: &Dir, ft: &'a str) -> Self {
PrefixFt { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns: ns.to_string(), ns,
_b: 0x2a, // * _b: 0x2a, // *
db: db.to_string(), db,
_c: 0x2a, // * _c: 0x2a, // *
tb: tb.to_string(), tb,
_d: 0x7e, // ~ _d: 0x7e, // ~
id: id.to_owned(), id: id.to_owned(),
eg: eg.to_owned(), eg: eg.to_owned(),
ft: ft.to_string(), ft,
} }
} }
} }
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
pub struct Graph { pub struct Graph<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub id: Id, pub id: Id,
pub eg: Dir, pub eg: Dir,
pub ft: String, pub ft: &'a str,
pub fk: Id, pub fk: Id,
} }
pub fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, fk: &Thing) -> Graph { pub fn new<'a>(
Graph::new( ns: &'a str,
ns.to_string(), db: &'a str,
db.to_string(), tb: &'a str,
tb.to_string(), id: &Id,
id.to_owned(), eg: &Dir,
eg.to_owned(), fk: &'a Thing,
fk.to_owned(), ) -> Graph<'a> {
) Graph::new(ns, db, tb, id.to_owned(), eg.to_owned(), fk)
} }
pub fn prefix(ns: &str, db: &str, tb: &str, id: &Id) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str, id: &Id) -> Vec<u8> {
@ -160,9 +160,9 @@ pub fn ftsuffix(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, ft: &str) -> Ve
k k
} }
impl Graph { impl<'a> Graph<'a> {
pub fn new(ns: String, db: String, tb: String, id: Id, eg: Dir, fk: Thing) -> Graph { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, id: Id, eg: Dir, fk: &'a Thing) -> Self {
Graph { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -173,8 +173,8 @@ impl Graph {
_d: 0x7e, // ~ _d: 0x7e, // ~
id, id,
eg, eg,
ft: fk.tb, ft: &fk.tb,
fk: fk.id, fk: fk.id.to_owned(),
} }
} }
} }
@ -185,14 +185,15 @@ mod tests {
fn key() { fn key() {
use super::*; use super::*;
use crate::sql::test::Parse; use crate::sql::test::Parse;
let fk = Thing::parse("other:test");
#[rustfmt::skip] #[rustfmt::skip]
let val = Graph::new( let val = Graph::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".into(), "test".into(),
Dir::Out, Dir::Out,
Thing::parse("other:test"), &fk,
); );
let enc = Graph::encode(&val).unwrap(); let enc = Graph::encode(&val).unwrap();
let dec = Graph::decode(&enc).unwrap(); let dec = Graph::decode(&enc).unwrap();

View file

@ -4,58 +4,58 @@ 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)]
struct Prefix { struct Prefix<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub ix: String, pub ix: &'a str,
} }
impl Prefix { impl<'a> Prefix<'a> {
fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Prefix { fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
Prefix { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns: ns.to_string(), ns,
_b: 0x2a, // * _b: 0x2a, // *
db: db.to_string(), db,
_c: 0x2a, // * _c: 0x2a, // *
tb: tb.to_string(), tb,
_d: 0xa4, // ¤ _d: 0xa4, // ¤
ix: ix.to_string(), ix,
} }
} }
} }
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)]
pub struct Index { pub struct Index<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub ix: String, pub ix: &'a str,
pub fd: Array, pub fd: Array,
pub id: Option<Id>, pub id: Option<Id>,
} }
pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: &Array, id: Option<&Id>) -> Index { pub fn new<'a>(
Index::new( ns: &'a str,
ns.to_string(), db: &'a str,
db.to_string(), tb: &'a str,
tb.to_string(), ix: &'a str,
ix.to_string(), fd: &Array,
fd.to_owned(), id: Option<&Id>,
id.cloned(), ) -> Index<'a> {
) Index::new(ns, db, tb, ix, fd.to_owned(), id.cloned())
} }
pub fn prefix(ns: &str, db: &str, tb: &str, ix: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str, ix: &str) -> Vec<u8> {
@ -70,9 +70,16 @@ pub fn suffix(ns: &str, db: &str, tb: &str, ix: &str) -> Vec<u8> {
k k
} }
impl Index { impl<'a> Index<'a> {
pub fn new(ns: String, db: String, tb: String, ix: String, fd: Array, id: Option<Id>) -> Index { pub fn new(
Index { ns: &'a str,
db: &'a str,
tb: &'a str,
ix: &'a str,
fd: Array,
id: Option<Id>,
) -> Self {
Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -95,10 +102,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Index::new( let val = Index::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
vec!["test"].into(), vec!["test"].into(),
Some("test".into()), Some("test".into()),
); );

View file

@ -2,22 +2,22 @@ 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 Ix { pub struct Ix<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub ix: String, pub ix: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Ix { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Ix<'a> {
Ix::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string()) Ix::new(ns, db, tb, ix)
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Ix { impl<'a> Ix<'a> {
pub fn new(ns: String, db: String, tb: String, ix: String) -> Ix { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self {
Ix { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -57,10 +57,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ix::new( let val = Ix::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Ix::encode(&val).unwrap(); let enc = Ix::encode(&val).unwrap();
let dec = Ix::decode(&enc).unwrap(); let dec = Ix::decode(&enc).unwrap();

View file

@ -3,25 +3,25 @@ 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 Lq { pub struct Lq<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub lq: Uuid, pub lq: Uuid,
} }
pub fn new(ns: &str, db: &str, lq: &Uuid) -> Lq { pub fn new<'a>(ns: &'a str, db: &'a str, lq: &Uuid) -> Lq<'a> {
Lq::new(ns.to_string(), db.to_string(), lq.to_owned()) Lq::new(ns, db, lq.to_owned())
} }
impl Lq { impl<'a> Lq<'a> {
pub fn new(ns: String, db: String, lq: Uuid) -> Lq { pub fn new(ns: &'a str, db: &'a str, lq: Uuid) -> Self {
Lq { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -42,8 +42,8 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Lq::new( let val = Lq::new(
"test".to_string(), "test",
"test".to_string(), "test",
Uuid::default(), Uuid::default(),
); );
let enc = Lq::encode(&val).unwrap(); let enc = Lq::encode(&val).unwrap();

View file

@ -3,22 +3,22 @@ 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 Lv { pub struct Lv<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub lv: Uuid, pub lv: Uuid,
} }
pub fn new(ns: &str, db: &str, tb: &str, lv: &Uuid) -> Lv { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, lv: &Uuid) -> Lv<'a> {
Lv::new(ns.to_string(), db.to_string(), tb.to_string(), lv.to_owned()) Lv::new(ns, db, tb, lv.to_owned())
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -33,9 +33,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Lv { impl<'a> Lv<'a> {
pub fn new(ns: String, db: String, tb: String, lv: Uuid) -> Lv { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, lv: Uuid) -> Self {
Lv { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -58,9 +58,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Lv::new( let val = Lv::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
Uuid::default(), Uuid::default(),
); );
let enc = Lv::encode(&val).unwrap(); let enc = Lv::encode(&val).unwrap();

View file

@ -2,19 +2,19 @@ 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 { pub struct Namespace<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
} }
pub fn new(ns: &str) -> Namespace { pub fn new<'a>(ns: &'a str) -> Namespace<'a> {
Namespace::new(ns.to_string()) Namespace::new(ns)
} }
impl Namespace { impl<'a> Namespace<'a> {
pub fn new(ns: String) -> Namespace { pub fn new(ns: &'a str) -> Self {
Namespace { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -29,7 +29,7 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Namespace::new( let val = Namespace::new(
"test".to_string(), "test",
); );
let enc = Namespace::encode(&val).unwrap(); let enc = Namespace::encode(&val).unwrap();
let dec = Namespace::decode(&enc).unwrap(); let dec = Namespace::decode(&enc).unwrap();

View file

@ -2,18 +2,18 @@ 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 { pub struct Nl<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
_c: u8, _c: u8,
_d: u8, _d: u8,
pub us: String, pub us: &'a str,
} }
pub fn new(ns: &str, us: &str) -> Nl { pub fn new<'a>(ns: &'a str, us: &'a str) -> Nl<'a> {
Nl::new(ns.to_string(), us.to_string()) Nl::new(ns, us)
} }
pub fn prefix(ns: &str) -> Vec<u8> { pub fn prefix(ns: &str) -> Vec<u8> {
@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec<u8> {
k k
} }
impl Nl { impl<'a> Nl<'a> {
pub fn new(ns: String, us: String) -> Nl { pub fn new(ns: &'a str, us: &'a str) -> Self {
Nl { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -49,8 +49,8 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Nl::new( let val = Nl::new(
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Nl::encode(&val).unwrap(); let enc = Nl::encode(&val).unwrap();
let dec = Nl::decode(&enc).unwrap(); let dec = Nl::decode(&enc).unwrap();

View file

@ -2,16 +2,16 @@ 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 Ns { pub struct Ns<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
_b: u8, _b: u8,
_c: u8, _c: u8,
pub ns: String, pub ns: &'a str,
} }
pub fn new(ns: &str) -> Ns { pub fn new<'a>(ns: &'a str) -> Ns<'a> {
Ns::new(ns.to_string()) Ns::new(ns)
} }
pub fn prefix() -> Vec<u8> { pub fn prefix() -> Vec<u8> {
@ -26,9 +26,9 @@ pub fn suffix() -> Vec<u8> {
k k
} }
impl Ns { impl<'a> Ns<'a> {
pub fn new(ns: String) -> Ns { pub fn new(ns: &'a str) -> Self {
Ns { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x21, // ! _a: 0x21, // !
_b: 0x6e, // n _b: 0x6e, // n
@ -45,7 +45,7 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Ns::new( let val = Ns::new(
"test".to_string(), "test",
); );
let enc = Ns::encode(&val).unwrap(); let enc = Ns::encode(&val).unwrap();
let dec = Ns::decode(&enc).unwrap(); let dec = Ns::decode(&enc).unwrap();

View file

@ -2,18 +2,18 @@ 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 { pub struct Nt<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
_c: u8, _c: u8,
_d: u8, _d: u8,
pub tk: String, pub tk: &'a str,
} }
pub fn new(ns: &str, tk: &str) -> Nt { pub fn new<'a>(ns: &'a str, tk: &'a str) -> Nt<'a> {
Nt::new(ns.to_string(), tk.to_string()) Nt::new(ns, tk)
} }
pub fn prefix(ns: &str) -> Vec<u8> { pub fn prefix(ns: &str) -> Vec<u8> {
@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec<u8> {
k k
} }
impl Nt { impl<'a> Nt<'a> {
pub fn new(ns: String, tk: String) -> Nt { pub fn new(ns: &'a str, tk: &'a str) -> Self {
Nt { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -49,8 +49,8 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Nt::new( let val = Nt::new(
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Nt::encode(&val).unwrap(); let enc = Nt::encode(&val).unwrap();
let dec = Nt::decode(&enc).unwrap(); let dec = Nt::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 Pa { pub struct Pa<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub pa: String, pub pa: &'a str,
} }
pub fn new(ns: &str, db: &str, pa: &str) -> Pa { pub fn new<'a>(ns: &'a str, db: &'a str, pa: &'a str) -> Pa<'a> {
Pa::new(ns.to_string(), db.to_string(), pa.to_string()) Pa::new(ns, db, pa)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Pa { impl<'a> Pa<'a> {
pub fn new(ns: String, db: String, pa: String) -> Pa { pub fn new(ns: &'a str, db: &'a str, pa: &'a str) -> Self {
Pa { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Pa::new( let val = Pa::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Pa::encode(&val).unwrap(); let enc = Pa::encode(&val).unwrap();
let dec = Pa::decode(&enc).unwrap(); let dec = Pa::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 Sc { pub struct Sc<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub sc: String, pub sc: &'a str,
} }
pub fn new(ns: &str, db: &str, sc: &str) -> Sc { pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str) -> Sc<'a> {
Sc::new(ns.to_string(), db.to_string(), sc.to_string()) Sc::new(ns, db, sc)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Sc { impl<'a> Sc<'a> {
pub fn new(ns: String, db: String, sc: String) -> Sc { pub fn new(ns: &'a str, db: &'a str, sc: &'a str) -> Self {
Sc { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Sc::new( let val = Sc::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Sc::encode(&val).unwrap(); let enc = Sc::encode(&val).unwrap();
let dec = Sc::decode(&enc).unwrap(); let dec = Sc::decode(&enc).unwrap();

View file

@ -2,23 +2,23 @@ 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 Scope { pub struct Scope<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub sc: String, pub sc: &'a str,
} }
pub fn new(ns: &str, db: &str, sc: &str) -> Scope { pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str) -> Scope<'a> {
Scope::new(ns.to_string(), db.to_string(), sc.to_string()) Scope::new(ns, db, sc)
} }
impl Scope { impl<'a> Scope<'a> {
pub fn new(ns: String, db: String, sc: String) -> Scope { pub fn new(ns: &'a str, db: &'a str, sc: &'a str) -> Self {
Scope { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -37,9 +37,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Scope::new( let val = Scope::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Scope::encode(&val).unwrap(); let enc = Scope::encode(&val).unwrap();
let dec = Scope::decode(&enc).unwrap(); let dec = Scope::decode(&enc).unwrap();

View file

@ -2,22 +2,22 @@ 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 { pub struct St<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub sc: String, pub sc: &'a str,
_d: u8, _d: u8,
_e: u8, _e: u8,
_f: u8, _f: u8,
pub tk: String, pub tk: &'a str,
} }
pub fn new(ns: &str, db: &str, sc: &str, tk: &str) -> St { pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> St<'a> {
St::new(ns.to_string(), db.to_string(), sc.to_string(), tk.to_string()) St::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> {
@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, sc: &str) -> Vec<u8> {
k k
} }
impl St { impl<'a> St<'a> {
pub fn new(ns: String, db: String, sc: String, tk: String) -> St { pub fn new(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> Self {
St { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -57,10 +57,10 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = St::new( let val = St::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = St::encode(&val).unwrap(); let enc = St::encode(&val).unwrap();
let dec = St::decode(&enc).unwrap(); let dec = St::decode(&enc).unwrap();

View file

@ -2,23 +2,23 @@ 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 Table { pub struct Table<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str) -> Table { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Table<'a> {
Table::new(ns.to_string(), db.to_string(), tb.to_string()) Table::new(ns, db, tb)
} }
impl Table { impl<'a> Table<'a> {
pub fn new(ns: String, db: String, tb: String) -> Table { pub fn new(ns: &'a str, db: &'a str, tb: &'a str) -> Self {
Table { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -37,9 +37,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Table::new( let val = Table::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Table::encode(&val).unwrap(); let enc = Table::encode(&val).unwrap();
let dec = Table::decode(&enc).unwrap(); let dec = Table::decode(&enc).unwrap();

View file

@ -2,20 +2,20 @@ 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 Tb { pub struct Tb<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
_d: u8, _d: u8,
_e: u8, _e: u8,
pub tb: String, pub tb: &'a str,
} }
pub fn new(ns: &str, db: &str, tb: &str) -> Tb { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Tb<'a> {
Tb::new(ns.to_string(), db.to_string(), tb.to_string()) Tb::new(ns, db, tb)
} }
pub fn prefix(ns: &str, db: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str) -> Vec<u8> {
@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec<u8> {
k k
} }
impl Tb { impl<'a> Tb<'a> {
pub fn new(ns: String, db: String, tb: String) -> Tb { pub fn new(ns: &'a str, db: &'a str, tb: &'a str) -> Self {
Tb { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -53,9 +53,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Tb::new( let val = Tb::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
); );
let enc = Tb::encode(&val).unwrap(); let enc = Tb::encode(&val).unwrap();
let dec = Tb::decode(&enc).unwrap(); let dec = Tb::decode(&enc).unwrap();

View file

@ -3,20 +3,20 @@ 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 Thing { pub struct Thing<'a> {
__: u8, __: u8,
_a: u8, _a: u8,
pub ns: String, pub ns: &'a str,
_b: u8, _b: u8,
pub db: String, pub db: &'a str,
_c: u8, _c: u8,
pub tb: String, pub tb: &'a str,
_d: u8, _d: u8,
pub id: Id, pub id: Id,
} }
pub fn new(ns: &str, db: &str, tb: &str, id: &Id) -> Thing { pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, id: &Id) -> Thing<'a> {
Thing::new(ns.to_string(), db.to_string(), tb.to_string(), id.to_owned()) Thing::new(ns, db, tb, id.to_owned())
} }
pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> { pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
@ -31,9 +31,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec<u8> {
k k
} }
impl Thing { impl<'a> Thing<'a> {
pub fn new(ns: String, db: String, tb: String, id: Id) -> Thing { pub fn new(ns: &'a str, db: &'a str, tb: &'a str, id: Id) -> Self {
Thing { Self {
__: 0x2f, // / __: 0x2f, // /
_a: 0x2a, // * _a: 0x2a, // *
ns, ns,
@ -54,9 +54,9 @@ mod tests {
use super::*; use super::*;
#[rustfmt::skip] #[rustfmt::skip]
let val = Thing::new( let val = Thing::new(
"test".to_string(), "test",
"test".to_string(), "test",
"test".to_string(), "test",
"test".into(), "test".into(),
); );
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
@ -69,7 +69,7 @@ mod tests {
// //
let id1 = "['test']"; let id1 = "['test']";
let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID"); let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID");
let val = Thing::new("test".to_string(), "test".to_string(), "test".to_string(), id1); let val = Thing::new("test", "test", "test", id1);
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
let dec = Thing::decode(&enc).unwrap(); let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);
@ -77,7 +77,7 @@ mod tests {
// //
let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']"; let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']";
let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID"); let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID");
let val = Thing::new("test".to_string(), "test".to_string(), "test".to_string(), id2); let val = Thing::new("test", "test", "test", id2);
let enc = Thing::encode(&val).unwrap(); let enc = Thing::encode(&val).unwrap();
let dec = Thing::decode(&enc).unwrap(); let dec = Thing::decode(&enc).unwrap();
assert_eq!(val, dec); assert_eq!(val, dec);

View file

@ -1035,7 +1035,8 @@ impl DefineFieldStatement {
// Claim transaction // Claim transaction
let mut run = run.lock().await; let mut run = run.lock().await;
// Process the statement // Process the statement
let key = crate::key::fd::new(opt.ns(), opt.db(), &self.what, &self.name.to_string()); let fd = self.name.to_string();
let key = crate::key::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?;

View file

@ -707,7 +707,8 @@ impl RemoveFieldStatement {
// Claim transaction // Claim transaction
let mut run = run.lock().await; let mut run = run.lock().await;
// Delete the definition // Delete the definition
let key = crate::key::fd::new(opt.ns(), opt.db(), &self.what, &self.name.to_string()); let fd = self.name.to_string();
let key = crate::key::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::fd::prefix(opt.ns(), opt.db(), &self.what);

View file

@ -27,6 +27,15 @@ pub struct Thing {
pub id: Id, pub id: Id,
} }
impl From<(&str, Id)> for Thing {
fn from((tb, id): (&str, Id)) -> Self {
Self {
tb: tb.to_owned(),
id,
}
}
}
impl From<(String, Id)> for Thing { impl From<(String, Id)> for Thing {
fn from((tb, id): (String, Id)) -> Self { fn from((tb, id): (String, Id)) -> Self {
Self { Self {