1
use std::error::Error as StdError;
2
use std::str::FromStr;
3

            
4
use log::LevelFilter;
5
use sqlx::{sqlite::SqliteConnectOptions, ConnectOptions, SqlitePool};
6

            
7
/// SQLite connection options.
8
pub struct Options {
9
    /// SQLite database file path. Use absolute/relative path.
10
    pub path: String,
11
}
12

            
13
/// Connect to SQLite.
14
13
pub async fn connect(options: &Options) -> Result<SqlitePool, Box<dyn StdError>> {
15
13
    let opts = SqliteConnectOptions::from_str(&options.path)?
16
13
        .create_if_missing(true)
17
13
        .log_statements(LevelFilter::Off);
18
36
    let result = SqlitePool::connect_with(opts).await?;
19
13
    Ok(result)
20
13
}