stringqb/tests/integration_test.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

2019-04-11 17:16:35 -04:00
use stringqb::query_builder::QueryBuilder;
#[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 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(?)");
}