use qail_core::parse;
use qail_core::transpiler::ToSql;
fn main() {
println!("=== Testing DISTINCT ON with Expressions ===\n");
let q1 = "get distinct on (phone_number) messages fields phone_number, content order by phone_number, created_at desc";
println!("Test 1 (DISTINCT ON column):");
match parse(q1) {
Ok(cmd) => println!(" OK: {}\n", cmd.to_sql()),
Err(e) => println!(" ERR: {}\n", e),
}
let q2 = r#"get distinct on (case when phone like '0%' then '62' || substring(phone from 2) else phone end) orders
fields phone, name order by case when phone like '0%' then '62' || substring(phone from 2) else phone end, created_at desc"#;
println!("Test 2 (DISTINCT ON CASE WHEN):");
match parse(q2) {
Ok(cmd) => println!(" OK: {}\n", cmd.to_sql()),
Err(e) => println!(" ERR: {}\n", e),
}
let q3 = "get distinct on (lower(email)) users fields email, name order by lower(email), id";
println!("Test 3 (DISTINCT ON function):");
match parse(q3) {
Ok(cmd) => println!(" OK: {}\n", cmd.to_sql()),
Err(e) => println!(" ERR: {}\n", e),
}
}