Silly SQL
SQL Query Construction Toolset
Basic usage:
var query = sql; queryotherTableJoin = 'INNER JOIN othertable ON othertable.mytableid = mytable.id'; queryfields = sql;queryfields ; querywhere = sql;querysort = sql;querylimit = sql; query;// => SELECT "mytable"."id" AS "myid", "mytable"."name" AS "myName", "othertable"."id" AS "otherId", "othertable"."name" AS "othername"// FROM mytable// INNER JOIN othertable ON othertable.mytableid = mytable.id// WHERE id > 5 AND (created_at < NOW() OR created_at IS NULL)// ORDER BY id DESC// LIMIT 10 OFFSET 5
Escaping values:
var query = sql; query;query; query;// => UPDATE mytable SET name=$1, age=$2query$values// => ['Alice', 38]
Inserting an object:
var query = sql; var myInput = name: 'Bob' age: 54;querycolumns = sql;queryvalues = sql; query;// => INSERT INTO mytable ("name", "age") VALUES $1, $2query$values// ['Bob', 54]
Authors
- Paul Frazee - Did everything
- John Fawcett - Initialized the git repo, named it