From 4ada6ac7e14d74e5995707fffed853ef3413b420 Mon Sep 17 00:00:00 2001 From: Lucille Blumire Date: Wed, 3 Nov 2021 01:07:56 +0000 Subject: [PATCH] Add support for serialized threading mode to sqlite (#1514) * Add support for serialized threading mode * Typos * Fix build --- sqlx-core/src/sqlite/connection/establish.rs | 10 +++++++--- sqlx-core/src/sqlite/options/mod.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sqlx-core/src/sqlite/connection/establish.rs b/sqlx-core/src/sqlite/connection/establish.rs index 401a673c..ce8105a6 100644 --- a/sqlx-core/src/sqlite/connection/establish.rs +++ b/sqlx-core/src/sqlite/connection/establish.rs @@ -7,8 +7,8 @@ use crate::{ }; use libsqlite3_sys::{ sqlite3_busy_timeout, sqlite3_extended_result_codes, sqlite3_open_v2, SQLITE_OK, - SQLITE_OPEN_CREATE, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE, - SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, + SQLITE_OPEN_CREATE, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, + SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, }; use sqlx_rt::blocking; use std::io; @@ -33,7 +33,11 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result, Cow<'static, str>>, + pub(crate) serialized: bool, } impl Default for SqliteConnectOptions { @@ -109,6 +110,7 @@ impl SqliteConnectOptions { log_settings: Default::default(), immutable: false, pragmas, + serialized: false, } } @@ -234,4 +236,14 @@ impl SqliteConnectOptions { self.immutable = immutable; self } + + /// Sets the [threading mode](https://www.sqlite.org/threadsafe.html) for the database connection. + /// + /// The default setting is `false` corersponding to using `OPEN_NOMUTEX`, if `true` then `OPEN_FULLMUTEX`. + /// + /// See [open](https://www.sqlite.org/c3ref/open.html) for more details. + pub fn serialized(mut self, serialized: bool) -> Self { + self.serialized = serialized; + self + } }