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
Changes from 2 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
@@ -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;
}

11 changes: 11 additions & 0 deletions sqlx-core/src/sqlite/options/mod.rs
Original file line number Diff line number Diff line change
@@ -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>>>,

@@ -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,
@@ -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 AsRef<str>) -> Self {
self.vfs = Some(Cow::Owned(vfs_name.as_ref().to_string()));
abonander marked this conversation as resolved.
Show resolved Hide resolved
self
}
}
2 changes: 2 additions & 0 deletions sqlx-core/src/sqlite/options/parse.rs
Original file line number Diff line number Diff line change
@@ -108,6 +108,8 @@ impl FromStr for SqliteConnectOptions {
}
},

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

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