//! Example: Query resource icons from the database //! //! This example shows how to retrieve processed resource icons for harvestables. //! Icons are 64x64 WebP images with white borders. use diesel::prelude::*; use diesel::sqlite::SqliteConnection; use std::env; fn main() -> Result<(), Box> { // Connect to database let database_url = env::var("DATABASE_URL").unwrap_or_else(|_| "../cursebreaker.db".to_string()); let mut conn = SqliteConnection::establish(&database_url)?; // Define the structure #[derive(Queryable, Debug)] struct ResourceIcon { item_id: i32, name: String, icon_64: Vec, } // Import schema use cursebreaker_parser::schema::resource_icons::dsl::*; // Query all resource icons let icons = resource_icons.load::(&mut conn)?; println!("šŸ“¦ Resource Icons Database"); println!("========================\n"); println!("Total icons: {}\n", icons.len()); for icon in icons { println!("Harvestable ID: {}", icon.item_id); println!(" Name: {}", icon.name); println!(" Icon size: {} bytes (WebP format, 64x64 with white border)", icon.icon_64.len()); println!(); } // Example: Get icon for a specific harvestable println!("\nšŸ” Looking up Copper Ore (harvestable_id = 2):"); let copper_icon = resource_icons .filter(item_id.eq(2)) .first::(&mut conn)?; println!(" Name: {}", copper_icon.name); println!(" Icon size: {} bytes", copper_icon.icon_64.len()); // You can save the icon to a file for testing: // std::fs::write("copper_ore.webp", &copper_icon.icon_64)?; Ok(()) }