summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs6
-rw-r--r--src/database.rs6
-rw-r--r--src/main.rs2
3 files changed, 9 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs
index 1300e9a..2f4bbd8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -19,6 +19,8 @@ pub struct Config {
pub log_level: String,
#[serde(default = "Config::default_max_body_size")]
pub max_body_size: u64,
+ #[serde(default = "Config::default_sqlite_thread_pool_size")]
+ pub sqlite_thread_pool_size: u32,
}
impl Config {
@@ -41,6 +43,10 @@ impl Config {
fn default_db_file() -> String {
String::from("kimikuri.db")
}
+
+ fn default_sqlite_thread_pool_size() -> u32 {
+ 16
+ }
}
diff --git a/src/database.rs b/src/database.rs
index a73aafd..07830a6 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -9,15 +9,13 @@ use crate::user::User;
pub type DbPool = sqlx::sqlite::SqlitePool;
-const SQLITE_THREAD_POOL_SIZE: u32 = 16;
-
-pub async fn open(file_path: &str) -> Result<DbPool, sqlx::Error> {
+pub async fn open(file_path: &str, sqlite_thread_pool_size: u32) -> Result<DbPool, sqlx::Error> {
let opt =
SqliteConnectOptions::from_str(format!("sqlite://{}", file_path).as_str())?
.create_if_missing(true);
debug!("Opening database pool...");
let pool = SqlitePoolOptions::new()
- .max_connections(SQLITE_THREAD_POOL_SIZE)
+ .max_connections(sqlite_thread_pool_size)
.connect_with(opt).await?;
// create table
diff --git a/src/main.rs b/src/main.rs
index 8ada3a0..e5cb1bb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -76,7 +76,7 @@ async fn main() {
let db = config.db_file.as_str();
info!(db, "Opening database...");
- let db: DbPool = database::open(db)
+ let db: DbPool = database::open(db, config.sqlite_thread_pool_size)
.await.expect(&*format!("cannot open database {}", db));
info!("Spawning bot coroutine...");