pixeluvw_supabase 0.1.0

A production-ready, high-performance Supabase SDK for Rust with middleware, retry logic, and Arc<Inner> architecture
Documentation
//! Example of using QueryBuilder with the 'countries' table.
//!
//! Run with: cargo run --example countries
//!
//! Requires a `.env` file with SUPABASE_URL and SUPABASE_KEY.

use dotenv::dotenv;
use pixeluvw_supabase::SupabaseClient;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct Country {
    id: i32,
    name: String,
    // Use Option for fields that might be missing or null to be safe
    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()?;

    // 1. Simple Select (Limit 5)
    println!("1️⃣  Fetching first 5 countries...");
    let countries: Vec<Country> = client
        .from("countries")
        .select("*")
        .limit(5)
        .order("name", true) // Order by name ascending
        .execute()
        .await?;

    for country in &countries {
        println!(
            "   - {} ({:?})",
            country.name,
            country.iso2.as_deref().unwrap_or("??")
        );
    }

    // 2. Filter with 'ilike' (Case insensitive search)
    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);
    }

    // 3. Complex Filter (AND condition)
    println!("\n3️⃣  Searching for countries in 'Asia' (if column exists) OR with ID > 200...");
    // Note: We use serde_json::Value here just in case 'continent' column doesn't exist
    // or schema is different than expected, to prevent deserialization errors crashing the demo.
    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"]);
    }

    // 4. Count
    println!("\n4️⃣  Counting total countries...");
    let count = client
        .from("countries")
        .select("*")
        .count("exact")
        .execute_count()
        .await?;

    println!("   Total: {}", count);

    Ok(())
}