felixfbecker / node-sql-template-strings

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

where in() doesn't work module #137

Closed viniciusbitt closed 4 years ago

viniciusbitt commented 4 years ago

I have an array of integers and to use with WHERE IN, I separate by comma

const in_categories = (await getCategoryTreeIDs(categoryID)).join(',');

let query = SQL`SELECT * FROM products WHERE CategoryID IN (${in_categories})`

After execute the query, seeing the MySQL log the query looks like this: SELECT * FROM products CategoryID IN ('1, 50, 51')

And it's not what I want, I need it to be a list, not a string. So, I tried to do it like this:

const in_categories = (await getCategoryTreeIDs(categoryID)).map(id =>"${id}").join(',');

Result (that also didn't work): IN ('\'\"1\"\',\'\"50\"\',\'\"51\"\'')