Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js sqlite3 IN operator

So I am currently trying to make a query in Node.js:

// friends is an array object
db.all('SELECT email ' +
       'FROM users' +
       'WHERE email in ?', friends, function(err, rows) {
           if (!err) {

I know that you can pass in an array of parameters for every '?' symbol, but is it possible to use the IN operator in this case? If not, should I do string concatenation or prepared statements?

like image 396
user1927638 Avatar asked Dec 18 '15 05:12

user1927638


1 Answers

db.all('SELECT email ' +
       'FROM users' +
       'WHERE email in ( ' + friends.map(function(){ return '?' }).join(',') + ' )', 
       friends, 
       function(err, rows) {
           if (!err) {
like image 115
asbel Avatar answered Oct 25 '22 18:10

asbel