use dotenv::dotenv;
use pixeluvw_supabase::SupabaseClient;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct Country {
id: i32,
name: String,
iso2: Option<String>,
continent: Option<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
println!("🌍 Countries Query Demo\n");
let client = SupabaseClient::from_env()?;
println!("1️⃣ Fetching first 5 countries...");
let countries: Vec<Country> = client
.from("countries")
.select("*")
.limit(5)
.order("name", true) .execute()
.await?;
for country in &countries {
println!(
" - {} ({:?})",
country.name,
country.iso2.as_deref().unwrap_or("??")
);
}
println!("\n2️⃣ Searching for countries with 'land' in the name...");
let land_countries: Vec<Country> = client
.from("countries")
.select("*")
.ilike("name", "%land%")
.limit(5)
.execute()
.await?;
for country in &land_countries {
println!(" - {}", country.name);
}
println!("\n3️⃣ Searching for countries in 'Asia' (if column exists) OR with ID > 200...");
let complex_results: Vec<serde_json::Value> = client
.from("countries")
.select("id, name, continent")
.gt("id", 200)
.limit(5)
.execute()
.await?;
for item in &complex_results {
println!(" - {} (ID: {})", item["name"], item["id"]);
}
println!("\n4️⃣ Counting total countries...");
let count = client
.from("countries")
.select("*")
.count("exact")
.execute_count()
.await?;
println!(" Total: {}", count);
Ok(())
}