mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
Support the immutable option on SQLite connections (#1289)
Co-authored-by: Austin Bonander <austin@launchbadge.com>
This commit is contained in:
parent
092f811f62
commit
687fbf9909
@ -29,8 +29,6 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
|
||||
})?
|
||||
.to_owned();
|
||||
|
||||
filename.push('\0');
|
||||
|
||||
// By default, we connect to an in-memory database.
|
||||
// [SQLITE_OPEN_NOMUTEX] will instruct [sqlite3_open_v2] to return an error if it
|
||||
// cannot satisfy our wish for a thread-safe, lock-free connection object
|
||||
@ -55,6 +53,13 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
|
||||
SQLITE_OPEN_PRIVATECACHE
|
||||
};
|
||||
|
||||
if options.immutable {
|
||||
filename = format!("file:{}?immutable=true", filename);
|
||||
flags |= libsqlite3_sys::SQLITE_OPEN_URI;
|
||||
}
|
||||
|
||||
filename.push('\0');
|
||||
|
||||
let busy_timeout = options.busy_timeout;
|
||||
|
||||
let handle = blocking!({
|
||||
|
||||
@ -63,6 +63,7 @@ pub struct SqliteConnectOptions {
|
||||
pub(crate) synchronous: SqliteSynchronous,
|
||||
pub(crate) auto_vacuum: SqliteAutoVacuum,
|
||||
pub(crate) page_size: u32,
|
||||
pub(crate) immutable: bool,
|
||||
}
|
||||
|
||||
impl Default for SqliteConnectOptions {
|
||||
@ -88,6 +89,7 @@ impl SqliteConnectOptions {
|
||||
synchronous: SqliteSynchronous::Full,
|
||||
auto_vacuum: Default::default(),
|
||||
page_size: 4096,
|
||||
immutable: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,6 +193,11 @@ impl SqliteConnectOptions {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn immutable(mut self, immutable: bool) -> Self {
|
||||
self.immutable = immutable;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the log settings.
|
||||
///
|
||||
/// # Example
|
||||
|
||||
@ -94,6 +94,20 @@ impl FromStr for SqliteConnectOptions {
|
||||
}
|
||||
},
|
||||
|
||||
"immutable" => match &*value {
|
||||
"true" | "1" => {
|
||||
options.immutable = true;
|
||||
}
|
||||
"false" | "0" => {
|
||||
options.immutable = false;
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!("unknown value {:?} for `immutable`", value).into(),
|
||||
));
|
||||
}
|
||||
},
|
||||
|
||||
_ => {
|
||||
return Err(Error::Configuration(
|
||||
format!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user