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
29
pub async fn connect(options: &Options) -> Result<SqlitePool, Box<dyn StdError>> {
15
29
    let opts = SqliteConnectOptions::from_str(&options.path)?
16
29
        .create_if_missing(true)
17
29
        .log_statements(LevelFilter::Off);
18
29
    let result = SqlitePool::connect_with(opts).await?;
19
29
    Ok(result)
20
29
}