use std::error::Error; type Result = std::result::Result>; pub mod db; pub mod fetch; pub mod score; #[cfg(test)] pub mod test_utils; pub struct AdapterPool(sqlx::SqlitePool); pub struct AdapterClient(reqwest::Client); 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 { let db = sqlx::sqlite::SqlitePoolOptions::new() .connect(&self.database_url).await?; sqlx::migrate!().run(&db).await?; let client = reqwest::Client::new(); Ok(Adapter { db: AdapterPool(db), client: AdapterClient(client) }) } } pub struct Adapter { db: AdapterPool, client: AdapterClient, } impl Adapter { pub fn get_pool(&self) -> &AdapterPool { &self.db } pub fn get_client(&self) -> &AdapterClient { &self.client } }