|
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 |
Answered by
tibbe
Nov 11, 2024
Replies: 3 comments 12 replies
|
You can add a |
3 replies
|
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. |
1 reply
|
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(); |
8 replies
Answer selected by
bikeshedder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's what I finally came up with with @bikeshedder's help: