mysqljs / sqlstring

Simple SQL escape and format for MySQL
MIT License
403 stars 78 forks source link

Add `and` separator option for `escape()` and as placeholder option in `format()` #33

Closed danjger closed 6 years ago

danjger commented 6 years ago

There is no support for dynamic object list expansion in the WHERE clause using this library. I added a new placeholder ?& that tells the .escape() function via a fourth parameter to use the word and instead of the default , to separate lists of values or arrays of objects. This allows the use of lists of objects in the WHERE clause correctly. This addresses this issue in stackoverflow: https://stackoverflow.com/questions/45380149/node-mysql-multiple-where-with-and-clause

dougwilson commented 6 years ago

This feature is not supported on purpose. The more expressive https://hiddentao.com/squel/ is what you want to use when you outgrow the simple replacements provided here.

dougwilson commented 6 years ago

On that note we really should get https://hiddentao.com/squel/ added to the README.

danjger commented 6 years ago

Why, then is this module a dependency of mysql? most people will inherit this by default so why not support a larger feature set here? I'll take a look at the alternative you suggest but I still think this simple upgrade isn't a violation of the goals of this library.

dougwilson commented 6 years ago

The MySql module is just a raw db driver and so only provides the simplest options. If you want more then the purpose is to use a higher level library / orm.