For hours now, am trying to query multiple database records and then insert into database using nodejs. The problem is that it only insert one rows per call instead of looping and inserting all database rows at once. can someone help me fix the issue.
con.query("SELECT * FROM users", function (err, result, fields) {
if (err) throw err;
console.log(result);
//You just insert a nested array of elements.
var sql = "INSERT INTO customers (name, address) VALUES ?";
var values = [[result[0].username], result[0].id]];
con.query(sql, [values], function (err, result) {
if (err) throw err;
console.log(" Number of records inserted: " + result.affectedRows);
});
});