felixfbecker / node-sql-template-strings

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

Append sql without modifying the original sql #164

Open guoqiao opened 3 years ago

guoqiao commented 3 years ago

The append method will modify the original sql in place. However, it's common that we need to define a common base sql (as const), and append different WHERE or ORDER BY conditons to it (to get a new SQL instance) for different situations, this is not available at the momment.

A suggested solution could be: In additional to the append method, we can also define a + operator, to return a new sql, without changing original one.

DenisFrezzato commented 3 years ago

I had the same issue, so I've created a wrapper that also introaduces immutability: https://github.com/DenisFrezzato/sql-template-strings-ts