Simplify datastore keys

This commit is contained in:
Tobie Morgan Hitchcock 2022-03-07 12:25:40 +00:00
parent 77844ab06b
commit 438b1d759c
21 changed files with 296 additions and 252 deletions

View file

@ -1,15 +1,14 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Database {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
}
impl From<Database> for Vec<u8> {
@ -31,10 +30,10 @@ pub fn new(ns: &str, db: &str) -> Database {
impl Database {
pub fn new(ns: String, db: String) -> Database {
Database {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
}
}

View file

@ -1,15 +1,16 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Db {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
__: char,
_a: char,
pub ns: String,
_b: char,
_c: char,
_d: char,
pub db: String,
}
impl From<Db> for Vec<u8> {
@ -31,10 +32,12 @@ pub fn new(ns: &str, db: &str) -> Db {
impl Db {
pub fn new(ns: String, db: String) -> Db {
Db {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("!db"),
_b: '!',
_c: 'd',
_d: 'b',
db,
}
}

View file

@ -1,17 +1,18 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Dl {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
us: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
_d: char,
_e: char,
pub dl: String,
}
impl From<Dl> for Vec<u8> {
@ -26,20 +27,22 @@ impl From<Vec<u8>> for Dl {
}
}
pub fn new(ns: &str, db: &str, us: &str) -> Dl {
Dl::new(ns.to_string(), db.to_string(), us.to_string())
pub fn new(ns: &str, db: &str, dl: &str) -> Dl {
Dl::new(ns.to_string(), db.to_string(), dl.to_string())
}
impl Dl {
pub fn new(ns: String, db: String, us: String) -> Dl {
pub fn new(ns: String, db: String, dl: String) -> Dl {
Dl {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("!us"),
us,
_c: '!',
_d: 'd',
_e: 'l',
dl,
}
}
pub fn encode(&self) -> Result<Vec<u8>, Error> {

View file

@ -1,17 +1,18 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Dt {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tk: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
_d: char,
_e: char,
pub tk: String,
}
impl From<Dt> for Vec<u8> {
@ -33,12 +34,14 @@ pub fn new(ns: &str, db: &str, tb: &str) -> Dt {
impl Dt {
pub fn new(ns: String, db: String, tk: String) -> Dt {
Dt {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("!tk"),
_c: '!',
_d: 'd',
_e: 't',
tk,
}
}

View file

@ -1,19 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Ev {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
ev: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
_e: char,
_f: char,
pub ev: String,
}
impl From<Ev> for Vec<u8> {
@ -35,14 +36,16 @@ pub fn new(ns: &str, db: &str, tb: &str, ev: &str) -> Ev {
impl Ev {
pub fn new(ns: String, db: String, tb: String, ev: String) -> Ev {
Ev {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("!ev"),
_d: '!',
_e: 'e',
_f: 'v',
ev,
}
}

View file

@ -1,19 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Fd {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
fd: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
_e: char,
_f: char,
pub fd: String,
}
impl From<Fd> for Vec<u8> {
@ -35,14 +36,16 @@ pub fn new(ns: &str, db: &str, tb: &str, fd: &str) -> Fd {
impl Fd {
pub fn new(ns: String, db: String, tb: String, fd: String) -> Fd {
Fd {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("!fd"),
_d: '!',
_e: 'f',
_f: 'd',
fd,
}
}

View file

@ -1,19 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Ft {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_d: String,
tb: String,
_c: String,
ft: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
_e: char,
_f: char,
pub ft: String,
}
impl From<Ft> for Vec<u8> {
@ -35,14 +36,16 @@ pub fn new(ns: &str, db: &str, tb: &str, ft: &str) -> Ft {
impl Ft {
pub fn new(ns: String, db: String, tb: String, ft: String) -> Ft {
Ft {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("!ft"),
_d: '!',
_e: 'f',
_f: 't',
ft,
}
}

View file

@ -1,21 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use crate::sql::value::Value;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Index {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
ix: String,
fd: Value,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
pub ix: String,
pub fd: Value,
}
impl From<Index> for Vec<u8> {
@ -37,14 +36,14 @@ pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value) -> Index {
impl Index {
pub fn new(ns: String, db: String, tb: String, ix: String, fd: Value) -> Index {
Index {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("¤"),
_d: '¤',
ix,
fd,
}

View file

@ -1,19 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Ix {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
ix: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
_e: char,
_f: char,
pub ix: String,
}
impl From<Ix> for Vec<u8> {
@ -35,14 +36,16 @@ pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Ix {
impl Ix {
pub fn new(ns: String, db: String, tb: String, ix: String) -> Ix {
Ix {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("!ix"),
_d: '!',
_e: 'i',
_f: 'x',
ix,
}
}

View file

@ -3,8 +3,6 @@ use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use serde::{Deserialize, Serialize};
// Default base key
pub const BASE: &str = "surreal";
// Ignore specifies an ignored field
pub const IGNORE: &str = "\x00";
// Prefix is the lowest char found in a key

View file

@ -1,19 +1,20 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Lv {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
lv: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
_e: char,
_f: char,
pub lv: String,
}
impl From<Lv> for Vec<u8> {
@ -35,14 +36,16 @@ pub fn new(ns: &str, db: &str, tb: &str, lv: &str) -> Lv {
impl Lv {
pub fn new(ns: String, db: String, tb: String, lv: String) -> Lv {
Lv {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("!lv"),
_d: '!',
_e: 'l',
_f: 'v',
lv,
}
}

View file

@ -1,13 +1,12 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Namespace {
kv: String,
_a: String,
ns: String,
__: char,
_a: char,
pub ns: String,
}
impl From<Namespace> for Vec<u8> {
@ -29,8 +28,8 @@ pub fn new(ns: &str) -> Namespace {
impl Namespace {
pub fn new(ns: String) -> Namespace {
Namespace {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
}
}

View file

@ -1,15 +1,16 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Nl {
kv: String,
_a: String,
ns: String,
_b: String,
us: String,
__: char,
_a: char,
pub ns: String,
_b: char,
_c: char,
_d: char,
pub us: String,
}
impl From<Nl> for Vec<u8> {
@ -31,10 +32,12 @@ pub fn new(ns: &str, us: &str) -> Nl {
impl Nl {
pub fn new(ns: String, us: String) -> Nl {
Nl {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("!us"),
_b: '!',
_c: 'n',
_d: 'l',
us,
}
}

View file

@ -1,13 +1,14 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Ns {
kv: String,
_a: String,
ns: String,
__: char,
_a: char,
_b: char,
_c: char,
pub ns: String,
}
impl From<Ns> for Vec<u8> {
@ -29,8 +30,10 @@ pub fn new(ns: &str) -> Ns {
impl Ns {
pub fn new(ns: String) -> Ns {
Ns {
kv: BASE.to_owned(),
_a: String::from("!ns"),
__: '/',
_a: '!',
_b: 'n',
_c: 's',
ns,
}
}

View file

@ -1,15 +1,16 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Nt {
kv: String,
_a: String,
ns: String,
_b: String,
tk: String,
__: char,
_a: char,
pub ns: String,
_b: char,
_c: char,
_d: char,
pub tk: String,
}
impl From<Nt> for Vec<u8> {
@ -31,10 +32,12 @@ pub fn new(ns: &str, tk: &str) -> Nt {
impl Nt {
pub fn new(ns: String, tk: String) -> Nt {
Nt {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("!tk"),
_b: '!',
_c: 'n',
_d: 't',
tk,
}
}

View file

@ -1,22 +1,21 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use crate::sql::value::Value;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Point {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
ix: String,
fd: Value,
id: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
pub ix: String,
pub fd: Value,
pub id: String,
}
impl From<Point> for Vec<u8> {
@ -38,14 +37,14 @@ pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value, id: &str) -> Point
impl Point {
pub fn new(ns: String, db: String, tb: String, ix: String, fd: Value, id: String) -> Point {
Point {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("¤"),
_d: '¤',
ix,
fd,
id,

View file

@ -1,17 +1,18 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Sc {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
sc: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
_d: char,
_e: char,
pub sc: String,
}
impl From<Sc> for Vec<u8> {
@ -33,12 +34,14 @@ pub fn new(ns: &str, db: &str, sc: &str) -> Sc {
impl Sc {
pub fn new(ns: String, db: String, sc: String) -> Sc {
Sc {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("!sc"),
_c: '!',
_d: 's',
_e: 'c',
sc,
}
}

View file

@ -1,19 +1,22 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct St {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
sc: String,
_d: String,
tk: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
_d: char,
_e: char,
pub sc: String,
_f: char,
_g: char,
_h: char,
pub tk: String,
}
impl From<St> for Vec<u8> {
@ -35,14 +38,18 @@ pub fn new(ns: &str, db: &str, sc: &str, tk: &str) -> St {
impl St {
pub fn new(ns: String, db: String, sc: String, tk: String) -> St {
St {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("!st"),
_c: '!',
_d: 's',
_e: 't',
sc,
_d: String::from("!tk"),
_f: '!',
_g: 't',
_h: 'k',
tk,
}
}

View file

@ -1,17 +1,16 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Table {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
}
impl From<Table> for Vec<u8> {
@ -33,12 +32,12 @@ pub fn new(ns: &str, db: &str, tb: &str) -> Table {
impl Table {
pub fn new(ns: String, db: String, tb: String) -> Table {
Table {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
}
}

View file

@ -1,17 +1,18 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Tb {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
_d: char,
_e: char,
pub tb: String,
}
impl From<Tb> for Vec<u8> {
@ -33,12 +34,14 @@ pub fn new(ns: &str, db: &str, tb: &str) -> Tb {
impl Tb {
pub fn new(ns: String, db: String, tb: String) -> Tb {
Tb {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("!tb"),
_c: '!',
_d: 't',
_e: 'b',
tb,
}
}

View file

@ -1,19 +1,18 @@
use crate::err::Error;
use crate::key::bytes::{deserialize, serialize};
use crate::key::BASE;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Thing {
kv: String,
_a: String,
ns: String,
_b: String,
db: String,
_c: String,
tb: String,
_d: String,
id: String,
__: char,
_a: char,
pub ns: String,
_b: char,
pub db: String,
_c: char,
pub tb: String,
_d: char,
pub id: String,
}
impl From<Thing> for Vec<u8> {
@ -28,6 +27,12 @@ impl From<Vec<u8>> for Thing {
}
}
impl From<&Vec<u8>> for Thing {
fn from(val: &Vec<u8>) -> Self {
Thing::decode(&val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, id: &str) -> Thing {
Thing::new(ns.to_string(), db.to_string(), tb.to_string(), id.to_string())
}
@ -35,14 +40,14 @@ pub fn new(ns: &str, db: &str, tb: &str, id: &str) -> Thing {
impl Thing {
pub fn new(ns: String, db: String, tb: String, id: String) -> Thing {
Thing {
kv: BASE.to_owned(),
_a: String::from("*"),
__: '/',
_a: '*',
ns,
_b: String::from("*"),
_b: '*',
db,
_c: String::from("*"),
_c: '*',
tb,
_d: String::from("*"),
_d: '*',
id,
}
}