diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -1,11 +1,14 @@ | |||
1 | use anyhow::Result; | 1 | use anyhow::Result; |
2 | use log::{debug, info}; | ||
2 | use rusqlite::{Connection, OpenFlags, NO_PARAMS}; | 3 | use rusqlite::{Connection, OpenFlags, NO_PARAMS}; |
3 | 4 | ||
5 | use std::fmt; | ||
4 | use std::path::Path; | 6 | use std::path::Path; |
5 | 7 | ||
6 | pub fn init_db<P: AsRef<Path>>(p: P) -> Result<Connection> { | 8 | pub fn init_db<P: AsRef<Path> + fmt::Display>(p: P) -> Result<Connection> { |
9 | debug!("Looking for database at `{}`", p); | ||
7 | let conn = Connection::open_with_flags( | 10 | let conn = Connection::open_with_flags( |
8 | p, | 11 | &p, |
9 | OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_READ_WRITE, | 12 | OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_READ_WRITE, |
10 | )?; | 13 | )?; |
11 | conn.execute( | 14 | conn.execute( |
@@ -15,5 +18,6 @@ pub fn init_db<P: AsRef<Path>>(p: P) -> Result<Connection> { | |||
15 | )", | 18 | )", |
16 | NO_PARAMS, | 19 | NO_PARAMS, |
17 | )?; | 20 | )?; |
21 | info!("SQLite3 database `{}` initialized", &p); | ||
18 | return Ok(conn); | 22 | return Ok(conn); |
19 | } | 23 | } |