2016-12-15 46 views
5

我無法使用node.js lib mysljs在我的數據庫中使用批量插入。如何使用mysljs在mySql和node.js中批量插入

我也跟着從答案:沒有成功

How do I do a bulk insert in mySQL using node.js

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' 

我也試圖promisify查詢mehod使用藍鳥,但沒有成功,我又得到同樣的錯誤。

回答

0

您需要標記與重音鑰匙(反引號)字符去掉方括號,就像這樣:'key`

讓您query這樣的:

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