我有100条数据,怎么用node插入到mysql在中啊,
我找了一种这样的但是不好
var query = 'insert into news set ?';
connection.query(query,{
title : 'node',
content : 'node',
nameConpany : 'woman',
time :'1512151'
}
我的数据结构是这样{{“title ”,“content ”,“nameConpany ”,“time ”},{“title ”,“content ”,“nameConpany ”,“time ”},......}求怎么做
用事务循环插入、如果有一条插入失败进行回滚
mysql模块、connection.beginTransaction是做事务
然后我这里封装了一个函数、对传入的数组做循环插入或更新之类的操作、如果有一条失败了就回滚、全对了就commit