felixfbecker / node-sql-template-strings

ES6 tagged template strings for prepared SQL statements 📋
ISC License
610 stars 40 forks source link

Add SQL.raw, allow queries to be nested #107

Open wolever opened 5 years ago

wolever commented 5 years ago

For example:

const columns = SQL.raw("foo, bar");
const whereClause = SQL`foo = ${someValue}`;
const query = SQL`SELECT ${columns} FROM table WHERE ${whereClause}`;

TODO:

const fields = {
    foo: 'hello',
    bar: 'world',
}
const updateClause = SQL.join(', ', Object.entries(fields).map(([col, val]) => {
    return SQL`${SQL.raw(escapeLiteral(col))} = ${val}`
})
const query = SQL`UPDATE table SET ${updateClause} WHERE ...`