Merge branch 'SeaQL:master' into master
This commit is contained in:
commit
a80df71c42
@ -122,21 +122,41 @@ impl ConnectOptions {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the maximum number of connections of the pool, if set
|
||||||
|
pub fn get_max_connections(&self) -> Option<u32> {
|
||||||
|
self.max_connections
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the minimum number of connections of the pool
|
/// Set the minimum number of connections of the pool
|
||||||
pub fn min_connections(&mut self, value: u32) -> &mut Self {
|
pub fn min_connections(&mut self, value: u32) -> &mut Self {
|
||||||
self.min_connections = Some(value);
|
self.min_connections = Some(value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the minimum number of connections of the pool, if set
|
||||||
|
pub fn get_min_connections(&self) -> Option<u32> {
|
||||||
|
self.min_connections
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the timeout duration when acquiring a connection
|
/// Set the timeout duration when acquiring a connection
|
||||||
pub fn connect_timeout(&mut self, value: Duration) -> &mut Self {
|
pub fn connect_timeout(&mut self, value: Duration) -> &mut Self {
|
||||||
self.connect_timeout = Some(value);
|
self.connect_timeout = Some(value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the timeout duration when acquiring a connection, if set
|
||||||
|
pub fn get_connect_timeout(&self) -> Option<Duration> {
|
||||||
|
self.connect_timeout
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the idle duration before closing a connection
|
/// Set the idle duration before closing a connection
|
||||||
pub fn idle_timeout(&mut self, value: Duration) -> &mut Self {
|
pub fn idle_timeout(&mut self, value: Duration) -> &mut Self {
|
||||||
self.idle_timeout = Some(value);
|
self.idle_timeout = Some(value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the idle duration before closing a connection, if set
|
||||||
|
pub fn get_idle_timeout(&self) -> Option<Duration> {
|
||||||
|
self.idle_timeout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ impl SqlxSqliteConnector {
|
|||||||
string.starts_with("sqlite:") && string.parse::<SqliteConnectOptions>().is_ok()
|
string.starts_with("sqlite:") && string.parse::<SqliteConnectOptions>().is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(mut options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||||
let mut opt = options
|
let mut opt = options
|
||||||
.url
|
.url
|
||||||
.parse::<SqliteConnectOptions>()
|
.parse::<SqliteConnectOptions>()
|
||||||
@ -37,12 +37,10 @@ impl SqlxSqliteConnector {
|
|||||||
use sqlx::ConnectOptions;
|
use sqlx::ConnectOptions;
|
||||||
opt.disable_statement_logging();
|
opt.disable_statement_logging();
|
||||||
}
|
}
|
||||||
if let Ok(pool) = options
|
if options.get_max_connections().is_none() {
|
||||||
.pool_options()
|
options.max_connections(1);
|
||||||
.max_connections(1)
|
}
|
||||||
.connect_with(opt)
|
if let Ok(pool) = options.pool_options().connect_with(opt).await {
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(DatabaseConnection::SqlxSqlitePoolConnection(
|
Ok(DatabaseConnection::SqlxSqlitePoolConnection(
|
||||||
SqlxSqlitePoolConnection { pool },
|
SqlxSqlitePoolConnection { pool },
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user