Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite open flags? #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions sqlite/src/config.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -40,6 +40,11 @@ pub struct Config {

/// [`Pool`] configuration.
pub pool: Option<PoolConfig>,

/// Sqlite OpenFlags
pub open_flags: Option<OpenFlags>,
// Sqlite VFS name (TODO)
// pub vfs: Option<String>,
}

impl Config {
Expand All @@ -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<PathBuf>, flags: OpenFlags) -> Self {
Self {
path: path.into(),
pool: None,
open_flags: Some(flags),
}
}

Expand Down
6 changes: 5 additions & 1 deletion sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ impl managed::Manager for Manager {

async fn create(&self) -> Result<Self::Type, Self::Error> {
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(
Expand Down
1 change: 1 addition & 0 deletions sqlite/tests/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down