53 lines
1.2 KiB
Rust
Raw Normal View History

2023-03-01 13:51:02 +03:00
use fstrings::f;
use fstrings::format_args_f;
use marine_sqlite_connector::Connection;
use marine_sqlite_connector::Result as SQLiteResult;
2023-03-01 13:51:02 +03:00
pub const DEFAULT_MAX_ERR_PARTICLES: usize = 50;
pub const DB_FILE: &'static str = "/tmp/db-5.sqlite";
#[derive(Debug)]
pub struct RegistryResult {
pub success: bool,
pub error: String,
}
pub fn wrapped_try<F, T>(func: F) -> T
where
F: FnOnce() -> T,
{
func()
}
pub struct Storage {
pub(crate) connection: Connection,
}
pub fn get_storage() -> SQLiteResult<Storage> {
marine_sqlite_connector::open("./tmp/db.sqlite").map(|c| Storage { connection: c })
}
2023-03-01 13:51:02 +03:00
pub fn db() -> Connection {
// use rand::prelude::*;
//
// let db_path = if std::path::Path::new("/tmp/this_is_test").exists() {
// format!("/tmp/{}_spell.sqlite", rand::random::<u32>())
// } else {
// format!(DB_FILE)
// };
marine_sqlite_connector::open(DB_FILE).expect("open sqlite db")
}
pub fn create() {
db().execute(f!(r#"
2023-03-01 13:51:02 +03:00
CREATE TABLE IF NOT EXISTS kv (
key TEXT NOT NULL,
string TEXT,
list_index INTEGER DEFAULT -1,
PRIMARY KEY(key, list_index)
);
"#))
2023-03-01 13:51:02 +03:00
.expect("init sqlite db");
}