Setup tables in a single init function

This commit is contained in:
Ethan O'Brien
2024-05-04 14:37:32 -05:00
parent 72f05a5d52
commit 32b5f5b68c
4 changed files with 26 additions and 39 deletions

View File

@@ -9,14 +9,15 @@ pub struct SQLite {
}
impl SQLite {
pub fn new(path: &str) -> SQLite {
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
let conn = Connection::open(path).unwrap();
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
SQLite {
let instance = SQLite {
engine: Mutex::new(conn),
sleep_duration: 10
}
};
setup(&instance);
instance
}
pub fn lock_and_exec(&self, command: &str, args: &[&dyn ToSql]) {
loop {