21 lines
588 B
Rust
21 lines
588 B
Rust
![]() |
use rusqlite::Connection;
|
||
|
use std::path::PathBuf;
|
||
|
|
||
|
static DB_INIT_QUERY: &'static str = include_str!("init.sql");
|
||
|
|
||
|
pub struct DbHandle {
|
||
|
conn: Connection,
|
||
|
}
|
||
|
|
||
|
impl DbHandle {
|
||
|
pub fn new(db_path: &Option<String>) -> DbHandle {
|
||
|
let path: PathBuf = db_path
|
||
|
.as_ref()
|
||
|
.map(|path: &String| PathBuf::from(path))
|
||
|
.unwrap_or_else(|| dirs::home_dir().unwrap().join(".foil").to_path_buf());
|
||
|
let conn: Connection = Connection::open(path).unwrap();
|
||
|
conn.execute_batch(DB_INIT_QUERY).unwrap();
|
||
|
DbHandle { conn: conn }
|
||
|
}
|
||
|
}
|