From 2df770a10bc38a23e0bae1c4db787c321f4df5dc Mon Sep 17 00:00:00 2001 From: Liam Gray Date: Fri, 31 May 2024 20:45:27 +0100 Subject: [PATCH] SqliteConnectOptions::filename() memory fix (#3136) (#3137) * SqliteConnectOptions::filename() memory fix (#3136) * Expose in_memory sqlite option * Docs SqliteConnectOptions::filename include mention of from_str alternative * Docs SqliteConnectOptions::filename typo fix --- sqlx-sqlite/src/options/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sqlx-sqlite/src/options/mod.rs b/sqlx-sqlite/src/options/mod.rs index b0093f3d..d3ed8b9f 100644 --- a/sqlx-sqlite/src/options/mod.rs +++ b/sqlx-sqlite/src/options/mod.rs @@ -210,6 +210,10 @@ impl SqliteConnectOptions { } /// Sets the name of the database file. + /// + /// This is a low-level API, and SQLx will apply no special treatment for `":memory:"` as an + /// in-memory database using this method. Using [SqliteConnectOptions::from_str] may be + /// preferred for simple use cases. pub fn filename(mut self, filename: impl AsRef) -> Self { self.filename = Cow::Owned(filename.as_ref().to_owned()); self @@ -228,6 +232,14 @@ impl SqliteConnectOptions { self.pragma("foreign_keys", if on { "ON" } else { "OFF" }) } + /// Set the [`SQLITE_OPEN_MEMORY` flag](https://sqlite.org/c3ref/open.html). + /// + /// By default, this is disabled. + pub fn in_memory(mut self, in_memory: bool) -> Self { + self.in_memory = in_memory; + self + } + /// Set the [`SQLITE_OPEN_SHAREDCACHE` flag](https://sqlite.org/sharedcache.html). /// /// By default, this is disabled.