From 856369e3705ab5cbc701cc296e30e3445cd2cb00 Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Fri, 15 Nov 2024 22:56:58 -0800 Subject: [PATCH] feat: connection pool in AppState --- src/state.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/state.rs b/src/state.rs index fa1e759..dcdb48b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,12 +2,14 @@ use std::{ collections::{hash_map::Entry, HashMap}, io::ErrorKind, path::{Path, PathBuf}, + str::FromStr, sync::Arc, }; use async_trait::async_trait; use chrono::{DateTime, Duration, Utc}; use serde::{Deserialize, Serialize}; +use sqlx::{sqlite::SqliteConnectOptions, SqlitePool}; use tokio::sync::Mutex; use crate::cache; @@ -54,12 +56,17 @@ impl Default for UploadRecord { #[derive(Clone)] pub struct AppState { pub records: Arc>>, + pub pool: SqlitePool, } impl AppState { pub fn new(records: HashMap) -> Self { Self { records: Arc::new(Mutex::new(records)), + pool: SqlitePool::connect_lazy_with( + SqliteConnectOptions::from_str("sqlite:testing.db") + .expect("Invalid Database String"), + ), } } }