How to massage inserts in mySql and node.js using mysljs

I was not able to use massive insertion in my DB using node.js lib mysljs .

I followed the answers:

How to perform bulk insert in mySQL using node.js

without success.

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(); }); 

I keep getting the error:

  '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' 

I also tried promising a mehod request using bluebird, but without success, I get the same error again.

+5
mysql bluebird
Dec 15 '16 at 18:20
source share
2 answers

Try removing the square brackets around the values

0
Aug 31 '17 at 16:19
source share

You must mark your keys with a backtick, for example: `key`

Creating a query as follows:

 var sql = "INSERT INTO resources (`resource_container_id`, `name`, `title`, `extension`, `mime_type`, `size`) VALUES ?"; 
0
Mar 10 '18 at 15:50
source share



All Articles