sql - Passing a key-value array in NodeJS for MySQL select query -
i can pass array mysql insert in nodejs so..
var data = {userid: 3, name: "sample"} db.query('insert my_table set ?', data, function(err, result){...}
is there similar way of passing array select query in clause... without specifying fields?
var data = {userid: 3, name: "sample"} db.query('select * my_table ?', data, function(err, result){...}
doesn't seem work.. nor using set name in place of 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]) + " , "; } whereclause = whereclause.substring(0, whereclause.length - 5); return whereclause; }); return updatedquery; };
this appears work.. e.g. var val = db.query('select * my_table ?', data, function(err, result) { }
Comments
Post a Comment