Set SqlxSqlit pool max connection to 1

This commit is contained in:
Billy Chan 2021-09-28 18:21:00 +08:00
parent 9bd537efe3
commit a1a7a98a5c
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7

View File

@ -1,5 +1,5 @@
use sqlx::{ use sqlx::{
sqlite::{SqliteArguments, SqliteQueryResult, SqliteRow}, sqlite::{SqliteArguments, SqlitePoolOptions, SqliteQueryResult, SqliteRow},
Sqlite, SqlitePool, Sqlite, SqlitePool,
}; };
@ -24,7 +24,11 @@ impl SqlxSqliteConnector {
} }
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> { pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
if let Ok(pool) = SqlitePool::connect(string).await { if let Ok(pool) = SqlitePoolOptions::new()
.max_connections(1)
.connect(string)
.await
{
Ok(DatabaseConnection::SqlxSqlitePoolConnection( Ok(DatabaseConnection::SqlxSqlitePoolConnection(
SqlxSqlitePoolConnection { pool }, SqlxSqlitePoolConnection { pool },
)) ))