Latest
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265import Q from "./mod.ts";import { test, assertStrictEq } from "./test_deps.ts";
test("static method - ", () => { const sql = Q.select("a", "b").from("hello").where({ a: 1 }).build(); assertStrictEq(sql, "SELECT `a`, `b` FROM `hello` WHERE `a`=1");});test("static method - ", () => { const sql = Q.select() .fields("a", "b") .table("hello") .where({ a: 1 }) .build(); assertStrictEq(sql, "SELECT `a`, `b` FROM `hello` WHERE `a`=1");});test("static method - ", () => { const sql = Q.insert({ a: 123, b: 456 }).into("hello").build(); assertStrictEq(sql, "INSERT INTO `hello` (`a`, `b`) VALUES (123, 456)");});test("static method - ", () => { const sql = Q.insert([ { a: 123, b: 456 }, { a: 789, b: 111 }, ]) .into("hello") .build(); assertStrictEq( sql, "INSERT INTO `hello` (`a`, `b`) VALUES (123, 456),\n(789, 111)", );});test("static method - ", () => { const sql = Q.update() .table("abc") .set({ a: 123, b: 456 }) .where({ c: 789 }) .build(); assertStrictEq(sql, "UPDATE `abc` SET `a`=123, `b`=456 WHERE `c`=789");});test("static method - ", () => { const sql = Q.delete().from("abc").where({ a: 666 }).limit(10).build(); assertStrictEq(sql, "DELETE FROM `abc` WHERE `a`=666 LIMIT 10");});
test("leftJoin - ", () => { const sql = Q.select("*") .from("hello") .as("A") .leftJoin("world") .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.* FROM `hello` AS `A` LEFT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("leftJoin - ", () => { const sql = Q.select("*") .from("hello") .as("A") .leftJoin("world", ["*"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.*, `B`.* FROM `hello` AS `A` LEFT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("leftJoin - ", () => { const sql = Q.select() .from("hello") .as("A") .leftJoin("world", ["*"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `B`.* FROM `hello` AS `A` LEFT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("leftJoin - ", () => { const sql = Q.select("x", "y") .from("hello") .as("A") .leftJoin("world", ["z"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.`x`, `A`.`y`, `B`.`z` FROM `hello` AS `A` LEFT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("leftJoin - ", () => { const sql = Q.select("x", "y") .from("hello") .leftJoin("world", ["z"]) .on("hello.id=world.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `hello`.`x`, `hello`.`y`, `world`.`z` FROM `hello` LEFT JOIN `world` ON hello.id=world.id WHERE 1 AND 2 LIMIT 2,3", );});
test("rightJoin - ", () => { const sql = Q.select("*") .from("hello") .as("A") .rightJoin("world", ["*"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.*, `B`.* FROM `hello` AS `A` RIGHT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("rightJoin - ", () => { const sql = Q.select("x", "y") .from("hello") .as("A") .rightJoin("world", ["z"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.`x`, `A`.`y`, `B`.`z` FROM `hello` AS `A` RIGHT JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("rightJoin - ", () => { const sql = Q.select("x", "y") .from("hello") .rightJoin("world", ["z"]) .on("hello.id=world.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `hello`.`x`, `hello`.`y`, `world`.`z` FROM `hello` RIGHT JOIN `world` ON hello.id=world.id WHERE 1 AND 2 LIMIT 2,3", );});
test("join - ", () => { const sql = Q.select("*") .from("hello") .as("A") .join("world", ["*"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.*, `B`.* FROM `hello` AS `A` JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("join - ", () => { const sql = Q.select("x", "y") .from("hello") .as("A") .join("world", ["z"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.`x`, `A`.`y`, `B`.`z` FROM `hello` AS `A` JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});test("join - ", () => { const sql = Q.select("x", "y") .from("hello") .join("world", ["z"]) .on("hello.id=world.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `hello`.`x`, `hello`.`y`, `world`.`z` FROM `hello` JOIN `world` ON hello.id=world.id WHERE 1 AND 2 LIMIT 2,3", );});test("join - ", () => { const sql = Q.select("x", "y") .from("hello") .as("A") .leftJoin("world", ["z"]) .as("B") .on("A.id=B.id") .leftJoin("world", ["k"]) .as("C") .on("B.uid=C.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.`x`, `A`.`y`, `B`.`z`, `C`.`k` FROM `hello` AS `A` LEFT JOIN `world` AS `B` ON A.id=B.id LEFT JOIN `world` AS `C` ON B.uid=C.id WHERE 1 AND 2 LIMIT 2,3", );});test("join - ", () => { const sql = Q.select("x", "y", "count(y) AS c1") .from("hello") .as("A") .join("world", ["z", "count(z) as c2"]) .as("B") .on("A.id=B.id") .where("1") .and("2") .offset(2) .limit(3) .build(); assertStrictEq( sql, "SELECT `A`.`x`, `A`.`y`, count(y) AS c1, `B`.`z`, count(z) as c2 FROM `hello` AS `A` JOIN `world` AS `B` ON A.id=B.id WHERE 1 AND 2 LIMIT 2,3", );});