From 94c656ad40a7aae570e5a5fb61ad32632acc6d46 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 23 Aug 2024 13:11:09 +0200 Subject: feat(treewide): Use a configuration file This allows use to avoid duplication of default values in the codebase and obviously also facilitates changing these without having to re-compile. --- src/app.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index f956251..b7d136e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,19 +8,20 @@ // You should have received a copy of the License along with this program. // If not, see . -use std::path::PathBuf; - use anyhow::{Context, Result}; use sqlx::{query, sqlite::SqliteConnectOptions, SqlitePool}; +use crate::config::Config; + pub struct App { pub database: SqlitePool, + pub config: Config, } impl App { - pub async fn new(db_name: PathBuf) -> Result { + pub async fn new(config: Config) -> Result { let options = SqliteConnectOptions::new() - .filename(db_name) + .filename(&config.paths.database_path) .optimize_on_close(true, None) .create_if_missing(true); @@ -32,6 +33,9 @@ impl App { .execute(&pool) .await?; - Ok(App { database: pool }) + Ok(App { + database: pool, + config, + }) } } -- cgit 1.4.1