turn on WAL mode
parent
bc97b8bc8f
commit
99c4a4e488
|
@ -205,6 +205,7 @@ pub fn insert_entry<C: Connection<Backend = Sqlite>>(
|
|||
#[derive(Debug)]
|
||||
pub struct ConnectionOptions {
|
||||
pub enable_foreign_keys: bool,
|
||||
pub enable_wal_mode: bool,
|
||||
pub busy_timeout: Option<Duration>,
|
||||
}
|
||||
|
||||
|
@ -213,6 +214,13 @@ impl ConnectionOptions {
|
|||
if self.enable_foreign_keys {
|
||||
conn.execute("PRAGMA foreign_keys = ON;")?;
|
||||
}
|
||||
|
||||
conn.execute(if self.enable_wal_mode {
|
||||
"PRAGMA journal_mode = WAL;"
|
||||
} else {
|
||||
"PRAGMA journal_mode = TRUNCATE;"
|
||||
})?;
|
||||
|
||||
if let Some(duration) = self.busy_timeout {
|
||||
conn.execute(&format!("PRAGMA busy_timeout = {};", duration.as_millis()))?;
|
||||
}
|
||||
|
@ -255,6 +263,7 @@ pub fn open_upend<P: AsRef<Path>>(
|
|||
let pool = r2d2::Pool::builder()
|
||||
.connection_customizer(Box::new(ConnectionOptions {
|
||||
enable_foreign_keys: true,
|
||||
enable_wal_mode: true,
|
||||
busy_timeout: Some(Duration::from_secs(30)),
|
||||
}))
|
||||
.build(manager)?;
|
||||
|
|
Loading…
Reference in New Issue