2016-12-15 16 views
5

kullanarak toplu yerleştirme DB'mde node.js lib mysljs'u kullanarak toplu eki kullanamıyorum. Hiçbir başarı ilemySql ve node.js mysljs

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

:

Ben cevaplar izledi. mavi kuş kullanılarak

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

Ben de sorguyu promisify çalıştı Metot ancak başarılı, yine aynı hatayı alıyorum:

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

ben alıyorum hatayı tutun.

cevap

0

böyle, values Sen aksan ile anahtarlarınızı işaretlemek gerekir

0

(backtick) karakteri köşeli parantezler kaldırmayı deneyin: `key`

yapma senin böyle query:

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