Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

我有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 ”},......}求怎么做


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
239 views
Welcome To Ask or Share your Answers For Others

1 Answer

用事务循环插入、如果有一条插入失败进行回滚

clipboard.png

mysql模块、connection.beginTransaction是做事务

然后我这里封装了一个函数、对传入的数组做循环插入或更新之类的操作、如果有一条失败了就回滚、全对了就commit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...