mod schema; pub mod users; use diesel::sqlite::SqliteConnection; use diesel::connection::SimpleConnection; use diesel::QueryResult; use diesel::r2d2::{ConnectionManager, Pool}; fn initialize_db(conn: &mut SqliteConnection) -> QueryResult<()> { // Enable WAL mode and enforce foreign keys conn.batch_execute("PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL; PRAGMA foreign_keys = ON;") } pub fn initialize_pool(url: &str) -> Pool> { let manager = ConnectionManager::new(url); let pool = Pool::builder().test_on_check_out(true).build(manager).expect("oops"); let mut conn = pool.get().unwrap(); initialize_db(&mut conn).unwrap(); pool }