ic_sqlite_vfs/db/
pragmas.rs1use crate::config::{BUSY_TIMEOUT_MS, SQLITE_CACHE_SIZE_KIB, SQLITE_PAGE_SIZE};
7use crate::db::connection::Connection;
8use crate::db::DbError;
9
10pub fn apply_read_write(connection: &Connection) -> Result<(), DbError> {
11 connection.execute_batch(&format!(
12 "PRAGMA page_size = {SQLITE_PAGE_SIZE};
13 PRAGMA journal_mode = MEMORY;
14 PRAGMA synchronous = OFF;
15 PRAGMA temp_store = MEMORY;
16 PRAGMA locking_mode = EXCLUSIVE;
17 PRAGMA foreign_keys = ON;
18 PRAGMA cache_size = -{SQLITE_CACHE_SIZE_KIB};
19 PRAGMA busy_timeout = {BUSY_TIMEOUT_MS};"
20 ))?;
21 Ok(())
22}
23
24pub fn apply_read_only(connection: &Connection) -> Result<(), DbError> {
25 connection.execute_batch(&format!(
26 "PRAGMA cache_size = -{SQLITE_CACHE_SIZE_KIB};
27 PRAGMA query_only = ON;
28 PRAGMA foreign_keys = ON;
29 PRAGMA temp_store = MEMORY;
30 PRAGMA busy_timeout = {BUSY_TIMEOUT_MS};"
31 ))?;
32 Ok(())
33}