use crate::types::Post; use sqlx::Sqlite; use sqlx::{self, sqlite}; use sqlx::{AnyPool, Pool}; use std::collections::BTreeMap; use std::sync::Arc; use std::sync::Mutex; use uuid::Uuid; #[derive(Clone)] pub struct AppState { pub posts: Arc>>, pub pool: Pool, } impl AppState { pub async fn new() -> Self { let pool = sqlite::SqlitePoolOptions::new() .max_connections(5) .connect(":memory:") .await .unwrap(); sqlx::migrate!("./migrations").run(&pool).await.unwrap(); Self { posts: Arc::new(Mutex::new(BTreeMap::new())), pool: pool, } } }