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

feat: allow vfs to be set as uri query parameter #2013

Merged
merged 3 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sqlx-core/src/sqlite/connection/establish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ impl EstablishParams {
SQLITE_OPEN_PRIVATECACHE
};

let mut query_params: Vec<String> = vec![];

if options.immutable {
filename = format!("file:{}?immutable=true", filename);
query_params.push("immutable=true".into())
}

if let Some(vfs) = &options.vfs {
query_params.push(format!("vfs={}", vfs))
}

if !query_params.is_empty() {
filename = format!("file:{}?{}", filename, query_params.join("&"));
flags |= libsqlite3_sys::SQLITE_OPEN_URI;
}

Expand Down
11 changes: 11 additions & 0 deletions sqlx-core/src/sqlite/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct SqliteConnectOptions {
pub(crate) busy_timeout: Duration,
pub(crate) log_settings: LogSettings,
pub(crate) immutable: bool,
pub(crate) vfs: Option<Cow<'static, str>>,

pub(crate) pragmas: IndexMap<Cow<'static, str>, Option<Cow<'static, str>>>,

Expand Down Expand Up @@ -135,6 +136,7 @@ impl SqliteConnectOptions {
busy_timeout: Duration::from_secs(5),
log_settings: Default::default(),
immutable: false,
vfs: None,
pragmas,
collations: Default::default(),
serialized: false,
Expand Down Expand Up @@ -367,4 +369,13 @@ impl SqliteConnectOptions {
self.row_channel_size = size;
self
}

/// Sets the [`vfs`](https://www.sqlite.org/vfs.html) parameter of the database connection.
///
/// The default value is empty, and sqlite will use the default VFS object dependeing on the
/// operating system.
pub fn vfs(mut self, vfs_name: impl Into<Cow<'static, str>>) -> Self {
self.vfs = Some(vfs_name.into());
self
}
}
2 changes: 2 additions & 0 deletions sqlx-core/src/sqlite/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl FromStr for SqliteConnectOptions {
}
},

"vfs" => options.vfs = Some(Cow::Owned(value.into_owned())),

_ => {
return Err(Error::Configuration(
format!(
Expand Down