-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sqlite: separate rw and ro connection pools (#412)
* sqlite: separate rw and ro connection pools * use the read_only connect option (potential source of issues)
- Loading branch information
Showing
9 changed files
with
71 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
use sqlx::migrate::MigrateError; | ||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions}; | ||
|
||
pub async fn init_db(filename: &str, in_memory: bool) -> Result<SqlitePool, MigrateError> { | ||
pub async fn init_db(filename: &str) -> Result<(SqlitePool, SqlitePool), MigrateError> { | ||
let options = SqliteConnectOptions::new() | ||
.filename(filename) | ||
.create_if_missing(true) | ||
.in_memory(in_memory) | ||
.synchronous(sqlx::sqlite::SqliteSynchronous::Normal) | ||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal) | ||
.foreign_keys(true); | ||
|
||
let conn = SqlitePoolOptions::new() | ||
let writer_conn = SqlitePoolOptions::new() | ||
.max_connections(1) | ||
.connect_with(options) | ||
.connect_with(options.clone().create_if_missing(true)) | ||
.await?; | ||
|
||
sqlx::migrate!().run(&conn).await?; | ||
let reader_conn = SqlitePoolOptions::new() | ||
.connect_with(options.read_only(true)) | ||
.await?; | ||
|
||
sqlx::migrate!().run(&writer_conn).await?; | ||
|
||
Ok(conn) | ||
Ok((reader_conn, writer_conn)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.