Node.js sqlite3 IN 运算符 [英] Node.js sqlite3 IN operator
本文介绍了Node.js sqlite3 IN 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我目前正在尝试在 Node.js 中进行查询:
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) {
我知道您可以为每个?"传递参数数组符号,但在这种情况下是否可以使用 IN 运算符?如果不是,我应该做字符串连接还是准备好的语句?
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?
推荐答案
db.all('SELECT email ' +
'FROM users' +
'WHERE email in ( ' + friends.map(function(){ return '?' }).join(',') + ' )',
friends,
function(err, rows) {
if (!err) {
这篇关于Node.js sqlite3 IN 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文