feat: connection pool in AppState
This commit is contained in:
parent
d55a906dde
commit
856369e370
1 changed files with 7 additions and 0 deletions
|
@ -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<Mutex<HashMap<String, UploadRecord>>>,
|
||||
pub pool: SqlitePool,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(records: HashMap<String, UploadRecord>) -> Self {
|
||||
Self {
|
||||
records: Arc::new(Mutex::new(records)),
|
||||
pool: SqlitePool::connect_lazy_with(
|
||||
SqliteConnectOptions::from_str("sqlite:testing.db")
|
||||
.expect("Invalid Database String"),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue