introduced a macro to make management of program properties easier program properties are obtained in this order: environment, .env file, commandline arguments a configuration file will be included at a later date and will be loaded between .env and commandline args
72 lines
1.6 KiB
Rust
72 lines
1.6 KiB
Rust
use std::fmt::Debug;
|
|
use std::sync::Mutex;
|
|
|
|
use sqlite::Connection;
|
|
use tracing::error;
|
|
use tracing::info;
|
|
|
|
use crate::PROPERTIES;
|
|
use crate::errors::DatabaseStoredError;
|
|
|
|
use super::DatabaseAccessor;
|
|
|
|
struct SQLiteDatabase {
|
|
connection: Mutex<Connection>,
|
|
}
|
|
|
|
impl SQLiteDatabase {
|
|
//fn lock(&self) {
|
|
|
|
//}
|
|
}
|
|
|
|
impl Debug for SQLiteDatabase {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_struct("SQLiteDatabase")/*.field("connection", &"<SQLiteConnection>")*/.finish()
|
|
}
|
|
}
|
|
|
|
impl DatabaseAccessor for SQLiteDatabase {
|
|
fn get_db_version(&self) {
|
|
todo!()
|
|
}
|
|
|
|
fn check_db_health(&self) {
|
|
todo!()
|
|
}
|
|
|
|
fn fix_db_health(&self) {
|
|
todo!()
|
|
}
|
|
|
|
fn is_dev(&self, user_id: serenity::all::UserId) -> bool {
|
|
todo!()
|
|
}
|
|
|
|
fn set_dev(&self, user_id: serenity::all::UserId) {
|
|
todo!()
|
|
}
|
|
|
|
fn store_error(&self, err: &DatabaseStoredError) {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
/// # Panics
|
|
/// This function will panic if used after the database has already been set
|
|
///
|
|
/// You should not worry about this as this function only ever gets called once at the start of the program and you are doing something wrong if you need to call this a second time
|
|
pub fn create_interface() -> Result<(), Box<dyn std::error::Error>> {
|
|
info!("Loading SQLite.");
|
|
if let Some(db_path) = PROPERTIES.dbpath.clone() {
|
|
let connection = sqlite::open(&db_path).map_err(|err| format!("Could not open file {db_path:?} with error: {err}"))?;
|
|
|
|
super::set_db(Box::new(SQLiteDatabase {
|
|
connection: /*Arc::new(*/Mutex::new(connection)/*)*/,
|
|
}));
|
|
|
|
Ok(())
|
|
} else {
|
|
Err("You must provide a path using `dbpath` for sqlite to function!".into())
|
|
}
|
|
}
|