Skip to content

Commit

Permalink
sql: enable shared cache
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Apr 17, 2021
1 parent e35a8d4 commit 9a34fe5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
12 changes: 4 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ serde = { version = "1.0", features = ["derive"] }
sha-1 = "0.9.3"
sha2 = "0.9.0"
smallvec = "1.0.0"
sqlx = { version = "0.5.2", features = ["runtime-async-std-native-tls", "sqlite"] }
sqlx = { git = "https://github.com/deltachat/sqlx", branch = "master", features = ["runtime-async-std-native-tls", "sqlite"] }
# keep in sync with sqlx
libsqlite3-sys = { version = "0.22.0", default-features = false, features = [ "pkg-config", "vcpkg", "bundled" ] }
stop-token = { version = "0.1.1", features = ["unstable"] }
Expand Down
3 changes: 3 additions & 0 deletions src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Sql {
.read_only(false)
.busy_timeout(Duration::from_secs(100))
.create_if_missing(true)
.shared_cache(true)
.synchronous(SqliteSynchronous::Normal);

PoolOptions::<Sqlite>::new()
Expand All @@ -112,6 +113,7 @@ PRAGMA temp_store=memory; -- Avoid SQLITE_IOERR_GETTEMPPATH errors on Android
.journal_mode(SqliteJournalMode::Wal)
.filename(dbfile.as_ref())
.read_only(readonly)
.shared_cache(true)
.busy_timeout(Duration::from_secs(100))
.synchronous(SqliteSynchronous::Normal);

Expand All @@ -122,6 +124,7 @@ PRAGMA temp_store=memory; -- Avoid SQLITE_IOERR_GETTEMPPATH errors on Android
let q = r#"
PRAGMA temp_store=memory; -- Avoid SQLITE_IOERR_GETTEMPPATH errors on Android
PRAGMA query_only=1; -- Protect against writes even in read-write mode
PRAGMA read_uncommitted=1; -- This helps avoid "table locked" errors in shared cache mode
"#;

conn.execute_many(sqlx::query(q))
Expand Down

0 comments on commit 9a34fe5

Please sign in to comment.