From 8338c23341138a902f561beb3d58c9150579e74a Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Fri, 29 Oct 2021 12:48:16 +0800 Subject: [PATCH] Do not override max_connections for SQLite --- src/database/mod.rs | 20 ++++++++++++++++++++ src/driver/sqlx_sqlite.rs | 12 +++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index 6a06a48ce..9a9710690 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -122,21 +122,41 @@ impl ConnectOptions { self } + /// Get the maximum number of connections of the pool, if set + pub fn get_max_connections(&self) -> Option { + self.max_connections + } + /// Set the minimum number of connections of the pool pub fn min_connections(&mut self, value: u32) -> &mut Self { self.min_connections = Some(value); self } + /// Get the minimum number of connections of the pool, if set + pub fn get_min_connections(&self) -> Option { + self.min_connections + } + /// Set the timeout duration when acquiring a connection pub fn connect_timeout(&mut self, value: Duration) -> &mut Self { self.connect_timeout = Some(value); self } + /// Get the timeout duration when acquiring a connection, if set + pub fn get_connect_timeout(&self) -> Option { + self.connect_timeout + } + /// Set the idle duration before closing a connection pub fn idle_timeout(&mut self, value: Duration) -> &mut Self { self.idle_timeout = Some(value); self } + + /// Get the idle duration before closing a connection, if set + pub fn get_idle_timeout(&self) -> Option { + self.idle_timeout + } } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 2001fac1b..d0f859e6c 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -28,7 +28,7 @@ impl SqlxSqliteConnector { string.starts_with("sqlite:") && string.parse::().is_ok() } - pub async fn connect(options: ConnectOptions) -> Result { + pub async fn connect(mut options: ConnectOptions) -> Result { let mut opt = options .url .parse::() @@ -37,12 +37,10 @@ impl SqlxSqliteConnector { use sqlx::ConnectOptions; opt.disable_statement_logging(); } - if let Ok(pool) = options - .pool_options() - .max_connections(1) - .connect_with(opt) - .await - { + if options.get_max_connections().is_none() { + options.max_connections(1); + } + if let Ok(pool) = options.pool_options().connect_with(opt).await { Ok(DatabaseConnection::SqlxSqlitePoolConnection( SqlxSqlitePoolConnection { pool }, ))