use stringqb::prelude::*; #[test] fn minimal_select_query() { let mut qb = QueryBuilder::default(); let sql = qb.from("foo").get_compiled_select(); assert_eq!(sql, "SELECT *\nFROM \"foo\""); } #[test] fn select_keys_as_query() { let mut qb = QueryBuilder::default(); let sql = qb.select("foo as bar, baz").from("a").get_compiled_select(); assert_eq!(sql, "SELECT \"foo\" as \"bar\",\"baz\"\nFROM \"a\""); } #[test] fn select_keys_query() { let mut qb = QueryBuilder::default(); let sql = qb.select("a, b, c").from("foo").get_compiled_select(); assert_eq!(sql, "SELECT \"a\",\"b\",\"c\"\nFROM \"foo\""); } #[test] fn select_vec_keys_query() { let mut qb = QueryBuilder::default(); let sql = qb .select_vec(vec!["a", "b", "c"]) .from("foo") .get_compiled_select(); assert_eq!(sql, "SELECT \"a\",\"b\",\"c\"\nFROM \"foo\""); } #[test] #[should_panic] fn select_without_from() { let qb = QueryBuilder::default(); qb.get_compiled_select(); } #[test] fn select_where() { let mut qb = QueryBuilder::default(); qb.from("test").r#where("foo", "bar"); let sql = qb.get_compiled_select(); let expected = "SELECT *\nFROM \"test\" WHERE \"foo\"=?"; assert_eq!(sql, expected); } #[test] fn select_where_in() { let mut qb = QueryBuilder::default(); qb.from("test").where_in("foo", vec![0, 1, 2, 3, 4, 5]); let sql = qb.get_compiled_select(); let expected = "SELECT *\nFROM \"test\" WHERE \"foo\" IN (?,?,?,?,?,?) "; assert_eq!(sql, expected); } #[test] fn basic_insert_query() { let mut qb = QueryBuilder::default(); qb.set("foo", Box::new("bar")); let sql = qb.get_compiled_insert("foobar"); assert_eq!(sql, "INSERT INTO \"foobar\" (\"foo\")\nVALUES(?)"); }