use std::path::Path; use serde::{Deserialize, Serialize}; use sqlx::sqlite::SqlitePool; #[derive(Clone, Debug, Serialize, Deserialize, sqlx::FromRow)] pub struct EtiGame { pub game_id: String, pub game_title: String, pub game_key: String, pub game_release: String, pub game_publisher: String, pub game_size: f64, pub game_readme_de: String, pub game_readme_en: String, pub game_readme_fr: String, pub game_maxplayers: u32, pub game_master_req: i32, pub genre_de: String, pub game_version: String, } /// # Errors pub async fn get_games(db: &Path) -> eyre::Result> { let pool = SqlitePool::connect(format!("sqlite:{}", db.to_string_lossy()).as_str()).await?; let mut games = sqlx::query_as::<_, EtiGame>( "SELECT g.game_id, g.game_title, g.game_key, g.game_release, g.game_publisher, CAST(g.game_size AS REAL) as game_size, g.game_readme_de, g.game_readme_en, g.game_readme_fr, CAST(g.game_maxplayers AS INTEGER) as game_maxplayers, g.game_master_req, ge.genre_de, g.game_version FROM games g JOIN genre ge ON g.genre_id = ge.genre_id", ) .fetch_all(&pool) .await?; games.sort_by(|a, b| a.game_title.cmp(&b.game_title)); tracing::info!("Found {} games in game.db", games.len()); for game in &games { tracing::debug!("{}: {}", game.game_id, game.game_title); } Ok(games) }