2026-02-05 12:05:43 -08:00
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
|
|
|
|
|
|
|
|
|
pub mod score;
|
2026-02-05 12:36:28 -08:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
pub mod test_utils;
|
|
|
|
|
|
2026-02-05 12:23:27 -08:00
|
|
|
pub struct AdapterPool(sqlx::SqlitePool);
|
|
|
|
|
pub struct AdapterBuilder {
|
|
|
|
|
database_url: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AdapterBuilder {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
database_url: "sqlite:test.db".to_string(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn database_url(mut self, url: &str) -> Self {
|
|
|
|
|
self.database_url = url.to_string();
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn create(self) -> Result<Adapter> {
|
|
|
|
|
let db = sqlx::sqlite::SqlitePoolOptions::new()
|
|
|
|
|
.connect(&self.database_url).await?;
|
|
|
|
|
sqlx::migrate!().run(&db).await?;
|
|
|
|
|
|
|
|
|
|
Ok(Adapter { db: AdapterPool(db) })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct Adapter {
|
|
|
|
|
db: AdapterPool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Adapter {
|
|
|
|
|
pub fn get_pool(&self) -> &AdapterPool { &self.db }
|
|
|
|
|
}
|