-
I'd like to run the following SQL statements against my SQLite database to run it in WAL mode: PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA busy_timeout = ...; In bb8 this would be a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
You can add a |
Beta Was this translation helpful? Give feedback.
-
This is what I eventually came up with: let pool = deadpool_diesel::sqlite::Pool::builder(manager)
.post_create(Hook::sync_fn(|obj, _| {
let mut conn = obj.lock().unwrap();
let res = conn.batch_execute(
r#"
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA busy_timeout = 5000;
"#,
);
match res {
Ok(_) => Ok(()),
// hopeless wrangling with error types here, idk how to get the diesel error
// into a HookError
Err(_err) => Err(HookError::message("error configuring database connection")),
}
}))
.build()
.unwrap(); I don't really know what I'm doing here. Not sure if taking that lock is a bad idea. Also the error handling is suboptimal. |
Beta Was this translation helpful? Give feedback.
-
Here's what I finally came up with with @bikeshedder's help: let pool = deadpool_diesel::sqlite::Pool::builder(manager)
.post_create(Hook::async_fn(|obj, _| {
Box::pin(async move {
let res = obj
.interact(|conn| {
conn.batch_execute(
r#"
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA busy_timeout = 5000;
"#,
)
})
.await;
match res {
Ok(_) => Ok(()),
// hopeless wrangling with error types here, idk how to get the diesel error
// into a HookError
Err(_err) => Err(HookError::message("error configuring database connection")),
}
})
}))
.build()
.unwrap(); |
Beta Was this translation helpful? Give feedback.
Here's what I finally came up with with @bikeshedder's help: