use sqlx::postgres::PgPoolOptions;
use sqlx::PgPool;
#[derive(Clone)]
pub struct AppState {
pub pool: PgPool,
}
impl AppState {
pub async fn connect(database_url: &str) -> anyhow::Result<Self> {
let pool = PgPoolOptions::new()
.max_connections(10)
.connect(database_url)
.await?;
Ok(Self { pool })
}
pub async fn migrate(&self) -> anyhow::Result<()> {
sqlx::migrate!("./migrations").run(&self.pool).await?;
Ok(())
}
}