diff --git a/app_env/src/config.rs b/app_env/src/config.rs index 964c118..fbdf58f 100644 --- a/app_env/src/config.rs +++ b/app_env/src/config.rs @@ -4,7 +4,9 @@ use serde::{Serialize,Deserialize,Deserializer}; use std::fmt; -use crate::DataStore; +use connectors::defs::StoreSettings; + +use datastores::defs::DataStore; #[derive(Clone, Debug, Deserialize)] pub struct Notifier { @@ -13,61 +15,6 @@ pub struct Notifier { pub command: String, } -#[derive(Clone, Debug, Deserialize, Default)] -pub struct StoreSettings { - host: String, - port: u32, - user: String, - pass: String, - pub database: String, - pub max_conn: u32, -} -impl StoreSettings { - #[must_use] - #[allow(unused_variables)] - pub fn url(&self, store: &str, key: &str) -> String { - let mut user_pass = String::from(""); - let user: String; - let pass: String; - user = self.user.to_owned(); - pass = self.pass.to_owned(); - if user.as_str() != "" || pass.as_str() != "" { - user_pass = format!("{}:{}", &user, &pass); - } - let host = &self.host; - let port = &self.port; - let database = &self.database; - format!( - "{}://{}@{}:{}/{}", - store, &user_pass, &host, &port, &database - ) - } -} -#[derive(Clone, Debug, Deserialize, Default)] -pub struct StoreKeyValue { - host: String, - port: u32, - pub prefix: String, - pub max_conn: u32, -} -impl StoreKeyValue { - #[must_use] - pub fn url(&self, store: &str) -> String { - let host = &self.host; - let port = &self.port; - format!("{}://{}:{}", store, &host, &port) - } -} -#[derive(Clone, Debug, Deserialize, Default)] -pub struct StoreLocal { - pub database: String, -} -impl StoreLocal { - #[must_use] - pub fn url(&self, store: &str) -> String { - format!("{}.{}", store, &self.database) - } -} #[derive(Clone, Debug, Deserialize, Default)] pub struct WebServer { pub name: String, @@ -206,6 +153,7 @@ pub struct Config { pub logs_path: String, pub logs_format: String, pub state_path: String, + pub datastores_settings: Vec, pub run_schedtasks: bool, pub schedtasks: Vec, pub run_websrvrs: bool, diff --git a/app_env/src/lib.rs b/app_env/src/lib.rs index 538a4a1..9072acb 100644 --- a/app_env/src/lib.rs +++ b/app_env/src/lib.rs @@ -62,59 +62,6 @@ pub async fn get_db_appdata() -> AppData { } */ -#[derive(Clone, Copy, Debug, PartialEq, Deserialize)] -/// `DataStore` options -pub enum DataStore { - File, - Mysql, // (sqlx::MySqlPool), - Postgres, // (sqlx::PgPool), - Sqlite, // (sqlx::SqlitePool), - Redis, // (redis::Client), - Tikv, // (tikv::RawClient), - Slab, // (Storage), - Unknown, -} - -pub type OptionDataStore = Option; - -impl Default for DataStore { - fn default() -> Self { - DataStore::Unknown - } -} -impl DataStore { - /// Get `DataStore`from String to enum - #[must_use] - pub fn get_from(str: String) -> DataStore { - match str.as_str() { - "file" | "File" => DataStore::File, - "mysql" | "Mysql" | "MySql" => DataStore::Mysql, - "postgres" | "Postgres" | "pg" => DataStore::Postgres, - "sqlite" | "Sqlite" => DataStore::Sqlite, - "redis" | "Redis" => DataStore::Redis, - "tikv" | "Tikv" => DataStore::Tikv, - "slab" | "Slab" => DataStore::Slab, - _ => DataStore::Unknown, - } - } -} - -#[allow(clippy::pattern_type_mismatch)] -impl fmt::Display for DataStore { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - DataStore::File => write!(f, "file"), - DataStore::Mysql => write!(f, "mysql"), - DataStore::Postgres => write!(f, "postgres"), - DataStore::Sqlite => write!(f, "sqlite"), - DataStore::Redis => write!(f, "redis"), - DataStore::Tikv => write!(f, "tikv"), - DataStore::Slab => write!(f, "slab"), - DataStore::Unknown => write!(f, "Unknown"), - } - } -} - #[derive(Clone, Copy, Debug, PartialEq)] /// `DataStore` options pub enum AppRunMode {