let orderQuery = `insert into orders (user_id,total_price) values (?,?)`
let params = [userId, totalPrice];
db.query(orderQuery, params, (error, result) => {
if (error) {
return callback(error);
} else {
let joinQuery = `insert into order_items (order_id,item_id,order_quantity) values ?`;
let params = orders.map((o) => {
return [result.insertId, o.itemId, o.quantity]
})
return db.query(joinQuery, [params], (error, result) => {
callback(error, result);
})
}
});
- insert into (a,b) values ?
- bulk insert: 여러개의 데이터를 한번에 넣기 위해 사용
- insert into (a,b) values (?,?)