use anyhow::Result; use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; use sqlx::SqlitePool; use std::path::Path; use std::str::FromStr; pub async fn connect(path: &Path) -> Result { let url = format!("sqlite://{}?mode=rwc", path.display()); let opts = SqliteConnectOptions::from_str(&url)? .create_if_missing(true) .foreign_keys(true); let pool = SqlitePoolOptions::new().max_connections(4).connect_with(opts).await?; Ok(pool) } pub async fn migrate(pool: &SqlitePool) -> Result<()> { sqlx::migrate!("./migrations").run(pool).await?; Ok(()) }