1
0
mirror of https://github.com/fluencelabs/sqlite-wasm-connector synced 2025-03-15 06:20:50 +00:00
2023-04-14 21:15:31 +03:00

53 lines
1.2 KiB
Rust

use fstrings::f;
use fstrings::format_args_f;
use marine_sqlite_connector::Connection;
use marine_sqlite_connector::Result as SQLiteResult;
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 })
}
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#"
CREATE TABLE IF NOT EXISTS kv (
key TEXT NOT NULL,
string TEXT,
list_index INTEGER DEFAULT -1,
PRIMARY KEY(key, list_index)
);
"#))
.expect("init sqlite db");
}