Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在NodeJS中为MySQL选择查询传递键值数组_Mysql_Sql_Node.js_Select - Fatal编程技术网

在NodeJS中为MySQL选择查询传递键值数组

在NodeJS中为MySQL选择查询传递键值数组,mysql,sql,node.js,select,Mysql,Sql,Node.js,Select,我可以在nodeJS中将一个数组传递给mysql insert,如下所示 var data = {userId: 3, name: "sample"} db.query('insert into my_table SET ?', data, function(err, result){...} 在where子句中是否有类似的方法将数组传递给select查询。。。不指定所有字段 var data = {userId: 3, name: "sample"} db.query('se

我可以在nodeJS中将一个数组传递给mysql insert,如下所示

var data = {userId: 3, name: "sample"}       
db.query('insert into my_table SET ?', data, function(err, result){...}
在where子句中是否有类似的方法将数组传递给select查询。。。不指定所有字段

var data = {userId: 3, name: "sample"} 
db.query('select * from my_table WHERE ?', data, function(err, result){...}
似乎不起作用。。使用集合名称代替where也不会

database.conn.config.defaultQueryFormat = function (query, values) {

if (!values) return query;
var updatedQuery = query.replace("?", function () {    
var whereClause = "";  
for(var index in values){
  whereClause += mysql.escapeId(index) + " = " + db.escape(values[index]) + " and ";
}

whereClause = whereClause.substring(0, whereClause.length - 5);

return whereClause;
});

return updatedQuery;
};
这似乎奏效了。。例如 var val=db.query('select*from my_table where?',数据,函数(err,result){ }