use compact_sql_traits::*; #[macro_use] extern crate compact_sql; enum QueryId { Sql1, Sql2, Sql3, Sql4, Sql5, Sql6, Sql7, Sql8, Sql9, } #[allow(dead_code)] #[derive(PgResultRow)] struct Ret { relname: String, relnamespace: u32, } #[test] fn test_opt() { pg_sql! { impl QueryId::Sql1 for Ret { SELECT relname, relnamespace, FROM pg_catalog.pg_class WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql1) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_opt2() { pg_sql! { impl QueryId::Sql2 for ?Ret { SELECT relname, relnamespace, FROM pg_catalog.pg_class WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql2) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_many() { pg_sql! { impl QueryId::Sql3 for *Ret { SELECT relname, relnamespace, FROM pg_catalog.pg_class WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql3) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_stream() { pg_sql! { impl QueryId::Sql4 for #Ret { SELECT relname, relnamespace, FROM pg_catalog.pg_class WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql4) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_exact_one() { pg_sql! { impl QueryId::Sql5 for =Ret { SELECT relname, relnamespace, FROM pg_catalog.pg_class WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql5) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_ignore() { pg_sql! { impl QueryId::Sql6 for ! { UPDATE pg_catalog.pg_class SET relname = relname, relnamespace = relnamespace, WHERE oid = {class_oid} RETURNING relname } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql6) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_dml_pure() { pg_sql! { impl QueryId::Sql7 { UPDATE pg_catalog.pg_class SET relname = relname, relnamespace = relnamespace, WHERE oid = {class_oid} } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql7) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_ddl() { pg_sql! { impl QueryId::Sql8 { CREATE SCHEMA IF NOT EXISTS public } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql8) { _test_trait(val) // Will emit error if trait does not match } } #[test] fn test_copy() { pg_sql! { impl QueryId::Sql9 { COPY pg_catalog.pg_namespace TO stdout } } fn _test_trait(_: &T) {} fn _test_struct(val: &Sql9) { _test_trait(val) // Will emit error if trait does not match } }