SQL Templates Tag
ES6 tag functions for SQL template strings.
WARNING: This project is still under development and the API is subject to change. A major overhaul to the API was introduced in v0.1.0.
DEMO
const sql = ; const usersTable = 'users';const usersTableColumns = 'id' 'email' 'password' 'active' 'created' 'modified'; const findUsersQuery = sql` SELECT FROM WHERE `; ;// => {// => text: 'SELECT "id", "email", "password", "active", "created", "modified" FROM users WHERE "email" = $1 AND "active" = $2',// => values: ['foo@bar.com', true]// => } ;// => {// => text: 'SELECT "id", "email", "password", "active", "created", "modified" FROM users WHERE TRUE',// => values: []// => } ;// => {// => text: 'SELECT "id", "email", "password", "active", "created", "modified" FROM users WHERE TRUE',// => values: []// => } const updateUsersQuery = sql` UPDATE SET WHERE "id" = `; ;// => {// => text: 'UPDATE users SET "email" = $1 , "modified" = $2 WHERE "id" = $3',// => values: ['foobar@example.com', "Mon Dec 07 2015 09:36:00 GMT-0500 (EST)", 4]// => }
License
MIT