Node.js sqlite3 IN operator

后端 未结 2 740
抹茶落季
抹茶落季 2021-02-14 07:27

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 ?\'         


        
相关标签:
2条回答
  • 2021-02-14 07:41
    db.all('SELECT email ' +
           'FROM users' +
           'WHERE email in ( ' + friends.map(function(){ return '?' }).join(',') + ' )', 
           friends, 
           function(err, rows) {
               if (!err) {
    
    0 讨论(0)
  • 2021-02-14 07:59

    Slight variation on asbel's great answer:

    db.all(
        `SELECT email FROM users WHERE email in (${ friends.fill('?') })`, 
        friends, 
        callback
    );
    
    0 讨论(0)
提交回复
热议问题