2022-08-08 19:44:35 +00:00
|
|
|
use crate::kvs::kv::Key;
|
|
|
|
use crate::sql::statements::DefineDatabaseStatement;
|
|
|
|
use crate::sql::statements::DefineEventStatement;
|
|
|
|
use crate::sql::statements::DefineFieldStatement;
|
|
|
|
use crate::sql::statements::DefineIndexStatement;
|
|
|
|
use crate::sql::statements::DefineLoginStatement;
|
|
|
|
use crate::sql::statements::DefineNamespaceStatement;
|
2023-01-09 12:43:47 +00:00
|
|
|
use crate::sql::statements::DefineParamStatement;
|
2022-08-08 19:44:35 +00:00
|
|
|
use crate::sql::statements::DefineScopeStatement;
|
|
|
|
use crate::sql::statements::DefineTableStatement;
|
|
|
|
use crate::sql::statements::DefineTokenStatement;
|
|
|
|
use crate::sql::statements::LiveStatement;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum Entry {
|
|
|
|
Ns(Arc<DefineNamespaceStatement>),
|
|
|
|
Db(Arc<DefineDatabaseStatement>),
|
|
|
|
Tb(Arc<DefineTableStatement>),
|
2022-09-22 23:54:53 +00:00
|
|
|
Nss(Arc<[DefineNamespaceStatement]>),
|
|
|
|
Nls(Arc<[DefineLoginStatement]>),
|
|
|
|
Nts(Arc<[DefineTokenStatement]>),
|
|
|
|
Dbs(Arc<[DefineDatabaseStatement]>),
|
|
|
|
Dls(Arc<[DefineLoginStatement]>),
|
|
|
|
Dts(Arc<[DefineTokenStatement]>),
|
|
|
|
Scs(Arc<[DefineScopeStatement]>),
|
|
|
|
Sts(Arc<[DefineTokenStatement]>),
|
2023-01-09 12:43:47 +00:00
|
|
|
Pas(Arc<[DefineParamStatement]>),
|
2022-09-22 23:54:53 +00:00
|
|
|
Tbs(Arc<[DefineTableStatement]>),
|
|
|
|
Evs(Arc<[DefineEventStatement]>),
|
|
|
|
Fds(Arc<[DefineFieldStatement]>),
|
|
|
|
Ixs(Arc<[DefineIndexStatement]>),
|
|
|
|
Fts(Arc<[DefineTableStatement]>),
|
|
|
|
Lvs(Arc<[LiveStatement]>),
|
2022-08-08 19:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Cache(pub HashMap<Key, Entry>);
|
|
|
|
|
|
|
|
impl Cache {
|
|
|
|
// Check if key exists
|
|
|
|
pub fn exi(&mut self, key: &Key) -> bool {
|
|
|
|
self.0.contains_key(key)
|
|
|
|
}
|
|
|
|
// Set a key in the cache
|
|
|
|
pub fn set(&mut self, key: Key, val: Entry) {
|
|
|
|
self.0.insert(key, val);
|
|
|
|
}
|
2022-12-18 10:23:07 +00:00
|
|
|
// Get a key from the cache
|
2022-08-08 19:44:35 +00:00
|
|
|
pub fn get(&mut self, key: &Key) -> Option<Entry> {
|
|
|
|
self.0.get(key).cloned()
|
|
|
|
}
|
2022-12-18 10:23:07 +00:00
|
|
|
// Delete a key from the cache
|
|
|
|
pub fn del(&mut self, key: &Key) -> Option<Entry> {
|
|
|
|
self.0.remove(key)
|
|
|
|
}
|
2022-08-08 19:44:35 +00:00
|
|
|
}
|