问题
I've looked into this answer
What I'm looking for is to be able to insert rows from a previous select query in nodejs and use the same RowDataPacket
and pass it to another insert query.
For instance, result from previous select call
[ RowDataPacket { user_id: 1024, session_id: 3, notification_id: 1 },
RowDataPacket { user_id: 1028, session_id: 3, notification_id: 2 } ] ]
following insert
var sql = 'INSERT INTO user_session_notification(user_id, session_id, notification_id) VALUES ?'
var values = []; // ???
回答1:
are you open to use ORM ? if yes you can use Sequelize ORM for node js with mysql driver . This ORM has feature for bulk insert click this link for to see documentation bulk insert. if no you need get the data from select and then merge the data (object) to array before bulk insert .. Hopefully can help you
来源:https://stackoverflow.com/questions/39563025/bulk-insert-mysql-but-from-arrays-of-objects