node-sql-template-strings icon indicating copy to clipboard operation
node-sql-template-strings copied to clipboard

Add SQL.raw, allow queries to be nested

Open wolever opened this issue 6 years ago • 0 comments

For example:

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

TODO:

  • [ ] TypeScript typings
  • [ ] Import more extensive unit tests
  • [ ] Introduce SQL.join helper:
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 ...`

wolever avatar Apr 02 '19 20:04 wolever