node-sql-template-strings
node-sql-template-strings copied to clipboard
Add SQL.raw, allow queries to be nested
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.joinhelper:
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 ...`