如何使用mysljs批量插入mySql和node.js [英] How to bulk insert in mySql and node.js using mysljs

查看:74
本文介绍了如何使用mysljs批量插入mySql和node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用node.js lib mysljs 在我的数据库中使用批量插入.

Im not able to use bulk insert in my DB using node.js lib mysljs.

我遵循了以下答案:

如何执行使用node.js在MySQL中批量插入

没有成功.

var sql = "INSERT INTO resources (resource_container_id, name, title, extension, mime_type, size) VALUES ?";

var values = [
  [1, 'pic1', 'title1', '.png', 'image/png', 500], 
  [1, 'pic2', 'title2', '.png', 'image/png', 700]];

return connection.query(sql, [values], (result) => {
    if (err) throw err;
    connection.end();
});

我不断收到错误消息:

 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'?\' at line 1' 

我还尝试使用bluebird来简化查询方法,但是没有成功,我再次遇到相同的错误.

I also tried to promisify the query mehod using bluebird but with no success, I get same error again.

推荐答案

尝试在问号附近使用()

try using () around the question mark

var sql = "INSERT INTO resources (resource_container_id, name, title, extension, mime_type, size) VALUES (?) ";

这篇关于如何使用mysljs批量插入mySql和node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆