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},
|
collections::{hash_map::Entry, HashMap},
|
||||||
io::ErrorKind,
|
io::ErrorKind,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
str::FromStr,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::cache;
|
use crate::cache;
|
||||||
|
@ -54,12 +56,17 @@ impl Default for UploadRecord {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub records: Arc<Mutex<HashMap<String, UploadRecord>>>,
|
pub records: Arc<Mutex<HashMap<String, UploadRecord>>>,
|
||||||
|
pub pool: SqlitePool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn new(records: HashMap<String, UploadRecord>) -> Self {
|
pub fn new(records: HashMap<String, UploadRecord>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
records: Arc::new(Mutex::new(records)),
|
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