The intention to execute multiple sql insert statements without running them into some kind of loop in node.js etc.
A typical sql statement looks like this.
INSERT INTO session_speaker(session_id, speaker_id) VALUES(?, ?);
INSERT INTO session_speaker(session_id, speaker_id) VALUES(?, ?);
OR
INSERT INTO session_speaker(session_id, speaker_id) VALUES(?, ?), (?, ?);
The ordinary node.js loop looks like this.
for (var i = 0; i < request.body.length; i++) {
queryRequest.sql += "INSERT INTO session_speaker(session_id, speaker_id) VALUES(?, ?);";
queryRequest.values.push(request.body[i].id, request.params.id);
}
Intention/Question:
Exploring a way if possible to pass request.body
to an intelligent SQL that takes array itself or maybe comma separated list of values and insert multiple rows from there without node.js loop.
request.body
looks like this (changeable to meet the requirements)
[
{
"id": 12
},
{
"id": 34
}
]