Base: Add basic DbBackend functions
This commit is contained in:
parent
3ef0229518
commit
ae19dfe8c1
|
@ -1,8 +1,26 @@
|
|||
use std::iter::Map;
|
||||
|
||||
mod sqlite;
|
||||
mod redis;
|
||||
|
||||
pub trait DbBackend {
|
||||
/// Connects to the DB
|
||||
fn connect(&self) -> Result<(), String>;
|
||||
|
||||
/// Get the map object at a key
|
||||
fn get(&self, key: &str) -> Result<Map<String, String>, String>;
|
||||
|
||||
/// Get the value inside a map object at a key (likely faster than get)
|
||||
fn get_inner(&self, key: &str, inner_key: &str) -> Result<String, String>;
|
||||
|
||||
/// Set the map object at a key, returns the value you game it
|
||||
fn set(&self, key: &str, value: Map<String, String>) -> Result<Map<String, String>, String>;
|
||||
|
||||
/// Set the value inside a map object at a key, returns the value you game it
|
||||
fn set_inner(&self, key: &str, inner_key: &str, value: &str) -> Result<&str, String>;
|
||||
|
||||
/// Disconnects from the DB
|
||||
fn disconnect(&self) -> Result<(), String>;
|
||||
}
|
||||
|
||||
pub fn get_backend_names() -> Vec<&'static str> {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::iter::Map;
|
||||
use crate::db::DbBackend;
|
||||
|
||||
pub(crate) struct RedisBackend {
|
||||
|
@ -11,4 +12,27 @@ impl RedisBackend {
|
|||
}
|
||||
|
||||
impl DbBackend for RedisBackend {
|
||||
fn connect(&self) -> Result<(), String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get(&self, key: &str) -> Result<Map<String, String>, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_inner(&self, key: &str, inner_key: &str) -> Result<String, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set(&self, key: &str, value: Map<String, String>) -> Result<Map<String, String>, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_inner(&self, key: &str, inner_key: &str, value: &str) -> Result<&str, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn disconnect(&self) -> Result<(), String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use std::iter::Map;
|
||||
use crate::db::DbBackend;
|
||||
|
||||
pub(crate) struct SqliteBackend {
|
||||
|
@ -11,4 +12,27 @@ impl SqliteBackend {
|
|||
}
|
||||
|
||||
impl DbBackend for SqliteBackend {
|
||||
fn connect(&self) -> Result<(), String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get(&self, key: &str) -> Result<Map<String, String>, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_inner(&self, key: &str, inner_key: &str) -> Result<String, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set(&self, key: &str, value: Map<String, String>) -> Result<Map<String, String>, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_inner(&self, key: &str, inner_key: &str, value: &str) -> Result<&str, String> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn disconnect(&self) -> Result<(), String> {
|
||||
todo!()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user