Node.js sqlite3 IN operator

女生的网名这么多〃 提交于 2019-12-04 20:49:34

问题


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?


回答1:


F.e.

db.all('SELECT email ' +
       'FROM users' +
       'WHERE email in ( ' + friends.map(function(){ return '?' }).join(',') + ' )', 
       friends, 
       function(err, rows) {
           if (!err) {


来源:https://stackoverflow.com/questions/34349199/node-js-sqlite3-in-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!