chore: init repo

This commit is contained in:
Jesús Pérez Lorenzo 2021-09-20 13:03:55 +01:00
commit cc2f02dfe6
6 changed files with 136 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

20
Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "datastores"
version = "0.1.0"
authors = ["JesusPerez <jpl@jesusperez.pro>"]
edition = "2018"
[dependencies]
anyhow = "1.0.40"
envmnt = "0.9.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
#tokio = { version = "1.5.0", features = ["full"] }
#redis = { version = "0.21.2", features = [ "tokio-comp", "cluster"] }
#slab = "0.4.4"
#sqlx = {version = "0.5.7", default-features = false, features = ["macros","runtime-tokio-rustls","sqlite", "mysql", "postgres", "decimal", "chrono"]}
#sthash = "0.2.11"
tempfile = "3.2.0"
#thiserror = "1.0.29"
# tikv-client = { git = "https://github.com/tikv/client-rust.git" }

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-2021 Jesús Pérez Lorenzo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

37
README.md Normal file
View File

@ -0,0 +1,37 @@
# Data Stores Defs Library
## Rust Library to define and manage [Data Stores](https://en.wikipedia.org/wiki/Data_store) for **LibreClouds** [Klouds](https://rlung.librecloud.online/LibreCloud/Klouds#klouds)
Part of the following developments:
- [CloudMandala](https://rlung.librecloud.online/LibreCloud/CloudMandala#cloudmandala)
- [Zteron](https://rlung.librecloud.online/LibreCloud/CloudMandala#cloudmandala)
It includes definitions and functions for the following [Data Stores](https://en.wikipedia.org/wiki/Data_store):
- Redis
- MySQL
- Postgres
- Sqlite
- Slab
### How to use
1 - Clone or download this lib in a path, better outside of target development
2 - Get current version from <u>Cargo.toml</u>
3 - Include a line like the one below in <u>target development Cargo.toml</u> (adjust version & path) and **use** whatever is need.
```toml
datastores = { version = "0.1.0", path = "../lib/datastores/defs" }
```
## Author
- [Jesús Pérez](https://info.jesusperez.pro).
## License
MIT

55
src/defs.rs Normal file
View File

@ -0,0 +1,55 @@
use serde::{Serialize,Deserialize};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, 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<DataStore>;
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"),
}
}
}

1
src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod defs;