diff --git a/sqlite/src/config.rs b/sqlite/src/config.rs index c18bc207..4a30a91e 100644 --- a/sqlite/src/config.rs +++ b/sqlite/src/config.rs @@ -1,6 +1,6 @@ -use std::{convert::Infallible, path::PathBuf}; - use crate::{CreatePoolError, Manager, Pool, PoolBuilder, PoolConfig, Runtime}; +use rusqlite::OpenFlags; +use std::{convert::Infallible, path::PathBuf}; /// Configuration object. /// @@ -40,6 +40,11 @@ pub struct Config { /// [`Pool`] configuration. pub pool: Option, + + /// Sqlite OpenFlags + pub open_flags: Option, + // Sqlite VFS name (TODO) + // pub vfs: Option, } impl Config { @@ -49,6 +54,17 @@ impl Config { Self { path: path.into(), pool: None, + open_flags: None, + } + } + + /// Create a new [`Config`] with the given `path` of SQLite database file and `flags`. + #[must_use] + pub fn new_with_flags(path: impl Into, flags: OpenFlags) -> Self { + Self { + path: path.into(), + pool: None, + open_flags: Some(flags), } } diff --git a/sqlite/src/lib.rs b/sqlite/src/lib.rs index a5c1e2b9..0ea90eea 100644 --- a/sqlite/src/lib.rs +++ b/sqlite/src/lib.rs @@ -78,7 +78,11 @@ impl managed::Manager for Manager { async fn create(&self) -> Result { let path = self.config.path.clone(); - SyncWrapper::new(self.runtime, move || rusqlite::Connection::open(path)).await + let flags = self.config.open_flags.unwrap_or_default(); + SyncWrapper::new(self.runtime, move || { + rusqlite::Connection::open_with_flags(path, flags) + }) + .await } async fn recycle( diff --git a/sqlite/tests/sqlite.rs b/sqlite/tests/sqlite.rs index 7caac13a..b6479eff 100644 --- a/sqlite/tests/sqlite.rs +++ b/sqlite/tests/sqlite.rs @@ -4,6 +4,7 @@ fn create_pool() -> Pool { let cfg = Config { path: "db.sqlite3".into(), pool: None, + open_flags: None, }; cfg.create_pool(Runtime::Tokio1).unwrap() }