From c295cb0509bd9565406fc8a7df943fd28c973490 Mon Sep 17 00:00:00 2001 From: Finn Bear Date: Sat, 29 Apr 2023 09:44:09 -0700 Subject: [PATCH] Optimization - Zero copy key deserialization. (#1880) --- Cargo.lock | 5 +- lib/Cargo.toml | 2 +- lib/src/key/database.rs | 20 +++--- lib/src/key/db.rs | 20 +++--- lib/src/key/dl.rs | 24 +++---- lib/src/key/dt.rs | 24 +++---- lib/src/key/ev.rs | 28 ++++---- lib/src/key/fc.rs | 24 +++---- lib/src/key/fd.rs | 28 ++++---- lib/src/key/ft.rs | 28 ++++---- lib/src/key/graph.rs | 111 ++++++++++++++++--------------- lib/src/key/index.rs | 73 +++++++++++--------- lib/src/key/ix.rs | 28 ++++---- lib/src/key/lq.rs | 20 +++--- lib/src/key/lv.rs | 24 +++---- lib/src/key/namespace.rs | 16 ++--- lib/src/key/nl.rs | 20 +++--- lib/src/key/ns.rs | 16 ++--- lib/src/key/nt.rs | 20 +++--- lib/src/key/pa.rs | 24 +++---- lib/src/key/sc.rs | 24 +++---- lib/src/key/scope.rs | 24 +++---- lib/src/key/st.rs | 28 ++++---- lib/src/key/table.rs | 24 +++---- lib/src/key/tb.rs | 24 +++---- lib/src/key/thing.rs | 28 ++++---- lib/src/sql/statements/define.rs | 3 +- lib/src/sql/statements/remove.rs | 3 +- lib/src/sql/thing.rs | 9 +++ 29 files changed, 371 insertions(+), 351 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03081047..bcaabf55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3710,11 +3710,12 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storekey" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "475592c1aa8849fa7874777c9df46aa93ffc47851c7c60bee88b1745a1adb893" +checksum = "43c42833834a5d23b344f71d87114e0cc9994766a5c42938f4b50e7b2aef85b2" dependencies = [ "byteorder", + "memchr", "serde", "thiserror", ] diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 7a8e4786..9c14d38b 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -92,7 +92,7 @@ serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.96" sha-1 = "0.10.1" sha2 = "0.10.6" -storekey = "0.4.1" +storekey = "0.5.0" thiserror = "1.0.40" tikv = { version = "0.1.0", package = "tikv-client", optional = true } tokio-util = { version = "0.7.7", optional = true, features = ["compat"] } diff --git a/lib/src/key/database.rs b/lib/src/key/database.rs index 9397a06c..d9bf5383 100644 --- a/lib/src/key/database.rs +++ b/lib/src/key/database.rs @@ -2,21 +2,21 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Database { +pub struct Database<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, } -pub fn new(ns: &str, db: &str) -> Database { - Database::new(ns.to_string(), db.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str) -> Database<'a> { + Database::new(ns, db) } -impl Database { - pub fn new(ns: String, db: String) -> Database { - Database { +impl<'a> Database<'a> { + pub fn new(ns: &'a str, db: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -33,8 +33,8 @@ mod tests { use super::*; #[rustfmt::skip] let val = Database::new( - "test".to_string(), - "test".to_string(), + "test", + "test", ); let enc = Database::encode(&val).unwrap(); let dec = Database::decode(&enc).unwrap(); diff --git a/lib/src/key/db.rs b/lib/src/key/db.rs index 3f0941e8..be447eff 100644 --- a/lib/src/key/db.rs +++ b/lib/src/key/db.rs @@ -2,18 +2,18 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Db { +pub struct Db<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, _c: u8, _d: u8, - pub db: String, + pub db: &'a str, } -pub fn new(ns: &str, db: &str) -> Db { - Db::new(ns.to_string(), db.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str) -> Db<'a> { + Db::new(ns, db) } pub fn prefix(ns: &str) -> Vec { @@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec { k } -impl Db { - pub fn new(ns: String, db: String) -> Db { - Db { +impl<'a> Db<'a> { + pub fn new(ns: &'a str, db: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -49,8 +49,8 @@ mod tests { use super::*; #[rustfmt::skip] let val = Db::new( - "test".to_string(), - "test".to_string(), + "test", + "test", ); let enc = Db::encode(&val).unwrap(); let dec = Db::decode(&enc).unwrap(); diff --git a/lib/src/key/dl.rs b/lib/src/key/dl.rs index d2ab4e7c..c6b851d7 100644 --- a/lib/src/key/dl.rs +++ b/lib/src/key/dl.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Dl { +pub struct Dl<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub dl: String, + pub dl: &'a str, } -pub fn new(ns: &str, db: &str, dl: &str) -> Dl { - Dl::new(ns.to_string(), db.to_string(), dl.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, dl: &'a str) -> Dl<'a> { + Dl::new(ns, db, dl) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Dl { - pub fn new(ns: String, db: String, dl: String) -> Dl { - Dl { +impl<'a> Dl<'a> { + pub fn new(ns: &'a str, db: &'a str, dl: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Dl::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Dl::encode(&val).unwrap(); let dec = Dl::decode(&enc).unwrap(); diff --git a/lib/src/key/dt.rs b/lib/src/key/dt.rs index d09c322a..5d68c486 100644 --- a/lib/src/key/dt.rs +++ b/lib/src/key/dt.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Dt { +pub struct Dt<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub tk: String, + pub tk: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str) -> Dt { - Dt::new(ns.to_string(), db.to_string(), tb.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Dt<'a> { + Dt::new(ns, db, tb) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Dt { - pub fn new(ns: String, db: String, tk: String) -> Dt { - Dt { +impl<'a> Dt<'a> { + pub fn new(ns: &'a str, db: &'a str, tk: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Dt::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Dt::encode(&val).unwrap(); let dec = Dt::decode(&enc).unwrap(); diff --git a/lib/src/key/ev.rs b/lib/src/key/ev.rs index e7f7e372..92904039 100644 --- a/lib/src/key/ev.rs +++ b/lib/src/key/ev.rs @@ -2,22 +2,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Ev { +pub struct Ev<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, _e: u8, _f: u8, - pub ev: String, + pub ev: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str, ev: &str) -> Ev { - Ev::new(ns.to_string(), db.to_string(), tb.to_string(), ev.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Ev<'a> { + Ev::new(ns, db, tb, ev) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Ev { - pub fn new(ns: String, db: String, tb: String, ev: String) -> Ev { - Ev { +impl<'a> Ev<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ev: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -57,10 +57,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = Ev::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", ); let enc = Ev::encode(&val).unwrap(); let dec = Ev::decode(&enc).unwrap(); diff --git a/lib/src/key/fc.rs b/lib/src/key/fc.rs index da42643e..cc2e5652 100644 --- a/lib/src/key/fc.rs +++ b/lib/src/key/fc.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Fc { +pub struct Fc<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub fc: String, + pub fc: &'a str, } -pub fn new(ns: &str, db: &str, fc: &str) -> Fc { - Fc::new(ns.to_string(), db.to_string(), fc.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, fc: &'a str) -> Fc<'a> { + Fc::new(ns, db, fc) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Fc { - pub fn new(ns: String, db: String, fc: String) -> Fc { - Fc { +impl<'a> Fc<'a> { + pub fn new(ns: &'a str, db: &'a str, fc: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Fc::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Fc::encode(&val).unwrap(); let dec = Fc::decode(&enc).unwrap(); diff --git a/lib/src/key/fd.rs b/lib/src/key/fd.rs index 1d61ba28..ee33bda2 100644 --- a/lib/src/key/fd.rs +++ b/lib/src/key/fd.rs @@ -2,22 +2,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Fd { +pub struct Fd<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, _e: u8, _f: u8, - pub fd: String, + pub fd: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str, fd: &str) -> Fd { - Fd::new(ns.to_string(), db.to_string(), tb.to_string(), fd.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, fd: &'a str) -> Fd<'a> { + Fd::new(ns, db, tb, fd) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Fd { - pub fn new(ns: String, db: String, tb: String, fd: String) -> Fd { - Fd { +impl<'a> Fd<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, fd: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -57,10 +57,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = Fd::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", ); let enc = Fd::encode(&val).unwrap(); let dec = Fd::decode(&enc).unwrap(); diff --git a/lib/src/key/ft.rs b/lib/src/key/ft.rs index 547d27cd..6042c3ad 100644 --- a/lib/src/key/ft.rs +++ b/lib/src/key/ft.rs @@ -2,22 +2,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Ft { +pub struct Ft<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, _e: u8, _f: u8, - pub ft: String, + pub ft: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str, ft: &str) -> Ft { - Ft::new(ns.to_string(), db.to_string(), tb.to_string(), ft.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ft: &'a str) -> Ft<'a> { + Ft::new(ns, db, tb, ft) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Ft { - pub fn new(ns: String, db: String, tb: String, ft: String) -> Ft { - Ft { +impl<'a> Ft<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ft: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -57,10 +57,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = Ft::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", ); let enc = Ft::encode(&val).unwrap(); let dec = Ft::decode(&enc).unwrap(); diff --git a/lib/src/key/graph.rs b/lib/src/key/graph.rs index 4c34e0fd..762c5989 100644 --- a/lib/src/key/graph.rs +++ b/lib/src/key/graph.rs @@ -5,28 +5,28 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -struct Prefix { +struct Prefix<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, pub id: Id, } -impl Prefix { - fn new(ns: &str, db: &str, tb: &str, id: &Id) -> Prefix { - Prefix { +impl<'a> Prefix<'a> { + fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * - ns: ns.to_string(), + ns, _b: 0x2a, // * - db: db.to_string(), + db, _c: 0x2a, // * - tb: tb.to_string(), + tb, _d: 0x7e, // ~ id: id.to_owned(), } @@ -34,29 +34,29 @@ impl Prefix { } #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -struct PrefixEg { +struct PrefixEg<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, pub id: Id, pub eg: Dir, } -impl PrefixEg { - fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir) -> PrefixEg { - PrefixEg { +impl<'a> PrefixEg<'a> { + fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id, eg: &Dir) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * - ns: ns.to_string(), + ns, _b: 0x2a, // * - db: db.to_string(), + db, _c: 0x2a, // * - tb: tb.to_string(), + tb, _d: 0x7e, // ~ id: id.to_owned(), eg: eg.to_owned(), @@ -65,63 +65,63 @@ impl PrefixEg { } #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -struct PrefixFt { +struct PrefixFt<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, pub id: Id, pub eg: Dir, - pub ft: String, + pub ft: &'a str, } -impl PrefixFt { - fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, ft: &str) -> PrefixFt { - PrefixFt { +impl<'a> PrefixFt<'a> { + fn new(ns: &'a str, db: &'a str, tb: &'a str, id: &Id, eg: &Dir, ft: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * - ns: ns.to_string(), + ns, _b: 0x2a, // * - db: db.to_string(), + db, _c: 0x2a, // * - tb: tb.to_string(), + tb, _d: 0x7e, // ~ id: id.to_owned(), eg: eg.to_owned(), - ft: ft.to_string(), + ft, } } } #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Graph { +pub struct Graph<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, pub id: Id, pub eg: Dir, - pub ft: String, + pub ft: &'a str, pub fk: Id, } -pub fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, fk: &Thing) -> Graph { - Graph::new( - ns.to_string(), - db.to_string(), - tb.to_string(), - id.to_owned(), - eg.to_owned(), - fk.to_owned(), - ) +pub fn new<'a>( + ns: &'a str, + db: &'a str, + tb: &'a str, + id: &Id, + eg: &Dir, + fk: &'a Thing, +) -> 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 { @@ -160,9 +160,9 @@ pub fn ftsuffix(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, ft: &str) -> Ve k } -impl Graph { - pub fn new(ns: String, db: String, tb: String, id: Id, eg: Dir, fk: Thing) -> Graph { - Graph { +impl<'a> Graph<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, id: Id, eg: Dir, fk: &'a Thing) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -173,8 +173,8 @@ impl Graph { _d: 0x7e, // ~ id, eg, - ft: fk.tb, - fk: fk.id, + ft: &fk.tb, + fk: fk.id.to_owned(), } } } @@ -185,14 +185,15 @@ mod tests { fn key() { use super::*; use crate::sql::test::Parse; + let fk = Thing::parse("other:test"); #[rustfmt::skip] let val = Graph::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", "test".into(), Dir::Out, - Thing::parse("other:test"), + &fk, ); let enc = Graph::encode(&val).unwrap(); let dec = Graph::decode(&enc).unwrap(); diff --git a/lib/src/key/index.rs b/lib/src/key/index.rs index 3fae9cdc..a560484a 100644 --- a/lib/src/key/index.rs +++ b/lib/src/key/index.rs @@ -4,58 +4,58 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -struct Prefix { +struct Prefix<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, - pub ix: String, + pub ix: &'a str, } -impl Prefix { - fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Prefix { - Prefix { +impl<'a> Prefix<'a> { + fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * - ns: ns.to_string(), + ns, _b: 0x2a, // * - db: db.to_string(), + db, _c: 0x2a, // * - tb: tb.to_string(), + tb, _d: 0xa4, // ยค - ix: ix.to_string(), + ix, } } } #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Index { +pub struct Index<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, - pub ix: String, + pub ix: &'a str, pub fd: Array, pub id: Option, } -pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: &Array, id: Option<&Id>) -> Index { - Index::new( - ns.to_string(), - db.to_string(), - tb.to_string(), - ix.to_string(), - fd.to_owned(), - id.cloned(), - ) +pub fn new<'a>( + ns: &'a str, + db: &'a str, + tb: &'a str, + ix: &'a str, + fd: &Array, + id: Option<&Id>, +) -> 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 { @@ -70,9 +70,16 @@ pub fn suffix(ns: &str, db: &str, tb: &str, ix: &str) -> Vec { k } -impl Index { - pub fn new(ns: String, db: String, tb: String, ix: String, fd: Array, id: Option) -> Index { - Index { +impl<'a> Index<'a> { + pub fn new( + ns: &'a str, + db: &'a str, + tb: &'a str, + ix: &'a str, + fd: Array, + id: Option, + ) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -95,10 +102,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = Index::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", vec!["test"].into(), Some("test".into()), ); diff --git a/lib/src/key/ix.rs b/lib/src/key/ix.rs index 99368765..0d28ab23 100644 --- a/lib/src/key/ix.rs +++ b/lib/src/key/ix.rs @@ -2,22 +2,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Ix { +pub struct Ix<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, _e: u8, _f: u8, - pub ix: String, + pub ix: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Ix { - Ix::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Ix<'a> { + Ix::new(ns, db, tb, ix) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Ix { - pub fn new(ns: String, db: String, tb: String, ix: String) -> Ix { - Ix { +impl<'a> Ix<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, ix: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -57,10 +57,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = Ix::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", ); let enc = Ix::encode(&val).unwrap(); let dec = Ix::decode(&enc).unwrap(); diff --git a/lib/src/key/lq.rs b/lib/src/key/lq.rs index 0a72463e..daa64bb0 100644 --- a/lib/src/key/lq.rs +++ b/lib/src/key/lq.rs @@ -3,25 +3,25 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Lq { +pub struct Lq<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, pub lq: Uuid, } -pub fn new(ns: &str, db: &str, lq: &Uuid) -> Lq { - Lq::new(ns.to_string(), db.to_string(), lq.to_owned()) +pub fn new<'a>(ns: &'a str, db: &'a str, lq: &Uuid) -> Lq<'a> { + Lq::new(ns, db, lq.to_owned()) } -impl Lq { - pub fn new(ns: String, db: String, lq: Uuid) -> Lq { - Lq { +impl<'a> Lq<'a> { + pub fn new(ns: &'a str, db: &'a str, lq: Uuid) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -42,8 +42,8 @@ mod tests { use super::*; #[rustfmt::skip] let val = Lq::new( - "test".to_string(), - "test".to_string(), + "test", + "test", Uuid::default(), ); let enc = Lq::encode(&val).unwrap(); diff --git a/lib/src/key/lv.rs b/lib/src/key/lv.rs index e43af6bf..51b13d06 100644 --- a/lib/src/key/lv.rs +++ b/lib/src/key/lv.rs @@ -3,22 +3,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Lv { +pub struct Lv<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, _e: u8, _f: u8, pub lv: Uuid, } -pub fn new(ns: &str, db: &str, tb: &str, lv: &Uuid) -> Lv { - Lv::new(ns.to_string(), db.to_string(), tb.to_string(), lv.to_owned()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, lv: &Uuid) -> Lv<'a> { + Lv::new(ns, db, tb, lv.to_owned()) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -33,9 +33,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Lv { - pub fn new(ns: String, db: String, tb: String, lv: Uuid) -> Lv { - Lv { +impl<'a> Lv<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, lv: Uuid) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -58,9 +58,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Lv::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", Uuid::default(), ); let enc = Lv::encode(&val).unwrap(); diff --git a/lib/src/key/namespace.rs b/lib/src/key/namespace.rs index 8bbbaf7c..3cd9a74a 100644 --- a/lib/src/key/namespace.rs +++ b/lib/src/key/namespace.rs @@ -2,19 +2,19 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Namespace { +pub struct Namespace<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, } -pub fn new(ns: &str) -> Namespace { - Namespace::new(ns.to_string()) +pub fn new<'a>(ns: &'a str) -> Namespace<'a> { + Namespace::new(ns) } -impl Namespace { - pub fn new(ns: String) -> Namespace { - Namespace { +impl<'a> Namespace<'a> { + pub fn new(ns: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -29,7 +29,7 @@ mod tests { use super::*; #[rustfmt::skip] let val = Namespace::new( - "test".to_string(), + "test", ); let enc = Namespace::encode(&val).unwrap(); let dec = Namespace::decode(&enc).unwrap(); diff --git a/lib/src/key/nl.rs b/lib/src/key/nl.rs index ccfa1e16..081cc8a5 100644 --- a/lib/src/key/nl.rs +++ b/lib/src/key/nl.rs @@ -2,18 +2,18 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Nl { +pub struct Nl<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, _c: u8, _d: u8, - pub us: String, + pub us: &'a str, } -pub fn new(ns: &str, us: &str) -> Nl { - Nl::new(ns.to_string(), us.to_string()) +pub fn new<'a>(ns: &'a str, us: &'a str) -> Nl<'a> { + Nl::new(ns, us) } pub fn prefix(ns: &str) -> Vec { @@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec { k } -impl Nl { - pub fn new(ns: String, us: String) -> Nl { - Nl { +impl<'a> Nl<'a> { + pub fn new(ns: &'a str, us: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -49,8 +49,8 @@ mod tests { use super::*; #[rustfmt::skip] let val = Nl::new( - "test".to_string(), - "test".to_string(), + "test", + "test", ); let enc = Nl::encode(&val).unwrap(); let dec = Nl::decode(&enc).unwrap(); diff --git a/lib/src/key/ns.rs b/lib/src/key/ns.rs index b7712dfd..32338d03 100644 --- a/lib/src/key/ns.rs +++ b/lib/src/key/ns.rs @@ -2,16 +2,16 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Ns { +pub struct Ns<'a> { __: u8, _a: u8, _b: u8, _c: u8, - pub ns: String, + pub ns: &'a str, } -pub fn new(ns: &str) -> Ns { - Ns::new(ns.to_string()) +pub fn new<'a>(ns: &'a str) -> Ns<'a> { + Ns::new(ns) } pub fn prefix() -> Vec { @@ -26,9 +26,9 @@ pub fn suffix() -> Vec { k } -impl Ns { - pub fn new(ns: String) -> Ns { - Ns { +impl<'a> Ns<'a> { + pub fn new(ns: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x21, // ! _b: 0x6e, // n @@ -45,7 +45,7 @@ mod tests { use super::*; #[rustfmt::skip] let val = Ns::new( - "test".to_string(), + "test", ); let enc = Ns::encode(&val).unwrap(); let dec = Ns::decode(&enc).unwrap(); diff --git a/lib/src/key/nt.rs b/lib/src/key/nt.rs index 1e9d0c5f..f505fc01 100644 --- a/lib/src/key/nt.rs +++ b/lib/src/key/nt.rs @@ -2,18 +2,18 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Nt { +pub struct Nt<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, _c: u8, _d: u8, - pub tk: String, + pub tk: &'a str, } -pub fn new(ns: &str, tk: &str) -> Nt { - Nt::new(ns.to_string(), tk.to_string()) +pub fn new<'a>(ns: &'a str, tk: &'a str) -> Nt<'a> { + Nt::new(ns, tk) } pub fn prefix(ns: &str) -> Vec { @@ -28,9 +28,9 @@ pub fn suffix(ns: &str) -> Vec { k } -impl Nt { - pub fn new(ns: String, tk: String) -> Nt { - Nt { +impl<'a> Nt<'a> { + pub fn new(ns: &'a str, tk: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -49,8 +49,8 @@ mod tests { use super::*; #[rustfmt::skip] let val = Nt::new( - "test".to_string(), - "test".to_string(), + "test", + "test", ); let enc = Nt::encode(&val).unwrap(); let dec = Nt::decode(&enc).unwrap(); diff --git a/lib/src/key/pa.rs b/lib/src/key/pa.rs index f887d168..1e727baa 100644 --- a/lib/src/key/pa.rs +++ b/lib/src/key/pa.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Pa { +pub struct Pa<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub pa: String, + pub pa: &'a str, } -pub fn new(ns: &str, db: &str, pa: &str) -> Pa { - Pa::new(ns.to_string(), db.to_string(), pa.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, pa: &'a str) -> Pa<'a> { + Pa::new(ns, db, pa) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Pa { - pub fn new(ns: String, db: String, pa: String) -> Pa { - Pa { +impl<'a> Pa<'a> { + pub fn new(ns: &'a str, db: &'a str, pa: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Pa::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Pa::encode(&val).unwrap(); let dec = Pa::decode(&enc).unwrap(); diff --git a/lib/src/key/sc.rs b/lib/src/key/sc.rs index 95180b8a..d92fb93d 100644 --- a/lib/src/key/sc.rs +++ b/lib/src/key/sc.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Sc { +pub struct Sc<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub sc: String, + pub sc: &'a str, } -pub fn new(ns: &str, db: &str, sc: &str) -> Sc { - Sc::new(ns.to_string(), db.to_string(), sc.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str) -> Sc<'a> { + Sc::new(ns, db, sc) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Sc { - pub fn new(ns: String, db: String, sc: String) -> Sc { - Sc { +impl<'a> Sc<'a> { + pub fn new(ns: &'a str, db: &'a str, sc: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Sc::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Sc::encode(&val).unwrap(); let dec = Sc::decode(&enc).unwrap(); diff --git a/lib/src/key/scope.rs b/lib/src/key/scope.rs index 5af568e1..a3b0abb0 100644 --- a/lib/src/key/scope.rs +++ b/lib/src/key/scope.rs @@ -2,23 +2,23 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Scope { +pub struct Scope<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub sc: String, + pub sc: &'a str, } -pub fn new(ns: &str, db: &str, sc: &str) -> Scope { - Scope::new(ns.to_string(), db.to_string(), sc.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str) -> Scope<'a> { + Scope::new(ns, db, sc) } -impl Scope { - pub fn new(ns: String, db: String, sc: String) -> Scope { - Scope { +impl<'a> Scope<'a> { + pub fn new(ns: &'a str, db: &'a str, sc: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -37,9 +37,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Scope::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Scope::encode(&val).unwrap(); let dec = Scope::decode(&enc).unwrap(); diff --git a/lib/src/key/st.rs b/lib/src/key/st.rs index e4382eeb..3f1675c7 100644 --- a/lib/src/key/st.rs +++ b/lib/src/key/st.rs @@ -2,22 +2,22 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct St { +pub struct St<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub sc: String, + pub sc: &'a str, _d: u8, _e: u8, _f: u8, - pub tk: String, + pub tk: &'a str, } -pub fn new(ns: &str, db: &str, sc: &str, tk: &str) -> St { - St::new(ns.to_string(), db.to_string(), sc.to_string(), tk.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> St<'a> { + St::new(ns, db, sc, tk) } pub fn prefix(ns: &str, db: &str, sc: &str) -> Vec { @@ -32,9 +32,9 @@ pub fn suffix(ns: &str, db: &str, sc: &str) -> Vec { k } -impl St { - pub fn new(ns: String, db: String, sc: String, tk: String) -> St { - St { +impl<'a> St<'a> { + pub fn new(ns: &'a str, db: &'a str, sc: &'a str, tk: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -57,10 +57,10 @@ mod tests { use super::*; #[rustfmt::skip] let val = St::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", + "test", ); let enc = St::encode(&val).unwrap(); let dec = St::decode(&enc).unwrap(); diff --git a/lib/src/key/table.rs b/lib/src/key/table.rs index a3bd8097..d92b37da 100644 --- a/lib/src/key/table.rs +++ b/lib/src/key/table.rs @@ -2,23 +2,23 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Table { +pub struct Table<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str) -> Table { - Table::new(ns.to_string(), db.to_string(), tb.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Table<'a> { + Table::new(ns, db, tb) } -impl Table { - pub fn new(ns: String, db: String, tb: String) -> Table { - Table { +impl<'a> Table<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -37,9 +37,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Table::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Table::encode(&val).unwrap(); let dec = Table::decode(&enc).unwrap(); diff --git a/lib/src/key/tb.rs b/lib/src/key/tb.rs index 117514dc..bbeb614b 100644 --- a/lib/src/key/tb.rs +++ b/lib/src/key/tb.rs @@ -2,20 +2,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Tb { +pub struct Tb<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, _d: u8, _e: u8, - pub tb: String, + pub tb: &'a str, } -pub fn new(ns: &str, db: &str, tb: &str) -> Tb { - Tb::new(ns.to_string(), db.to_string(), tb.to_string()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str) -> Tb<'a> { + Tb::new(ns, db, tb) } pub fn prefix(ns: &str, db: &str) -> Vec { @@ -30,9 +30,9 @@ pub fn suffix(ns: &str, db: &str) -> Vec { k } -impl Tb { - pub fn new(ns: String, db: String, tb: String) -> Tb { - Tb { +impl<'a> Tb<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -53,9 +53,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Tb::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", ); let enc = Tb::encode(&val).unwrap(); let dec = Tb::decode(&enc).unwrap(); diff --git a/lib/src/key/thing.rs b/lib/src/key/thing.rs index 92d0935e..db217031 100644 --- a/lib/src/key/thing.rs +++ b/lib/src/key/thing.rs @@ -3,20 +3,20 @@ use derive::Key; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Key)] -pub struct Thing { +pub struct Thing<'a> { __: u8, _a: u8, - pub ns: String, + pub ns: &'a str, _b: u8, - pub db: String, + pub db: &'a str, _c: u8, - pub tb: String, + pub tb: &'a str, _d: u8, pub id: Id, } -pub fn new(ns: &str, db: &str, tb: &str, id: &Id) -> Thing { - Thing::new(ns.to_string(), db.to_string(), tb.to_string(), id.to_owned()) +pub fn new<'a>(ns: &'a str, db: &'a str, tb: &'a str, id: &Id) -> Thing<'a> { + Thing::new(ns, db, tb, id.to_owned()) } pub fn prefix(ns: &str, db: &str, tb: &str) -> Vec { @@ -31,9 +31,9 @@ pub fn suffix(ns: &str, db: &str, tb: &str) -> Vec { k } -impl Thing { - pub fn new(ns: String, db: String, tb: String, id: Id) -> Thing { - Thing { +impl<'a> Thing<'a> { + pub fn new(ns: &'a str, db: &'a str, tb: &'a str, id: Id) -> Self { + Self { __: 0x2f, // / _a: 0x2a, // * ns, @@ -54,9 +54,9 @@ mod tests { use super::*; #[rustfmt::skip] let val = Thing::new( - "test".to_string(), - "test".to_string(), - "test".to_string(), + "test", + "test", + "test", "test".into(), ); let enc = Thing::encode(&val).unwrap(); @@ -69,7 +69,7 @@ mod tests { // let id1 = "['test']"; 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 dec = Thing::decode(&enc).unwrap(); assert_eq!(val, dec); @@ -77,7 +77,7 @@ mod tests { // let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']"; 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 dec = Thing::decode(&enc).unwrap(); assert_eq!(val, dec); diff --git a/lib/src/sql/statements/define.rs b/lib/src/sql/statements/define.rs index 2a978259..57702390 100644 --- a/lib/src/sql/statements/define.rs +++ b/lib/src/sql/statements/define.rs @@ -1035,7 +1035,8 @@ impl DefineFieldStatement { // Claim transaction let mut run = run.lock().await; // 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_db(opt.ns(), opt.db(), opt.strict).await?; run.add_tb(opt.ns(), opt.db(), &self.what, opt.strict).await?; diff --git a/lib/src/sql/statements/remove.rs b/lib/src/sql/statements/remove.rs index fa8d1a51..bbddad18 100644 --- a/lib/src/sql/statements/remove.rs +++ b/lib/src/sql/statements/remove.rs @@ -707,7 +707,8 @@ impl RemoveFieldStatement { // Claim transaction let mut run = run.lock().await; // 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?; // Clear the cache let key = crate::key::fd::prefix(opt.ns(), opt.db(), &self.what); diff --git a/lib/src/sql/thing.rs b/lib/src/sql/thing.rs index 5c48a872..00c231de 100644 --- a/lib/src/sql/thing.rs +++ b/lib/src/sql/thing.rs @@ -27,6 +27,15 @@ pub struct Thing { 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 { fn from((tb, id): (String, Id)) -> Self { Self {