use sqlx::Pool; use sqlx::Sqlite; use sqlx::{self, sqlite}; #[derive(Clone)] pub struct ServerState { pub pool: Pool, } impl ServerState { pub async fn new() -> Self { // This is almost certainly bad practice for more reasons than I can count dotenvy::dotenv().ok(); let db_url = dotenvy::var("DATABASE_URL").unwrap_or("sqlite:./db.sqlite".to_string()); let pool = sqlite::SqlitePoolOptions::new() .max_connections(5) .connect(&db_url) .await .unwrap(); sqlx::migrate!("./migrations").run(&pool).await.unwrap(); Self { // posts: Arc::new(Mutex::new(BTreeMap::new())), pool: pool, } } }