Inserting a big Array into MariaDB with a promise

I’m trying to insert a big object into my database (mariaDB).I don’t understand if the error comes from the format of my array or from my SQL request.

First of all, I convert this object to a array for my query.

let values = jsonObj.reduce((o, f) => {       let ini = [] ini.push(moment(f.date, "DD/MM/YYYY hh:mm").format("YYYY-MM-DD HH:mm:ss"))       ini.push(parseInt(f.val))       ini.push("x")       o.push(ini)       return o     }, []) 

After this I do my query with my mariaDb pool :

let query = "INSERT INTO data_sycomore (date, valeur, codePS) VALUES ?" let promise = new Promise((resolve, reject) => {         pool.query(query, valuesQuery, (error, result) => {           console.log(result)           if (error) {             reject(error)           }           else {             resolve(result)           }         })       }) 

My table contains a little over 50,000 values. However, I only insert the first value game of my object. I can’t understand where the problem is coming from. Thank you in advance for your help.

Array :

[[ '2019-04-01 03:00:00', -25, 'CODE1' ],   [ '2019-04-01 03:10:00', -1112, 'CODE1' ],   [ '2019-04-01 03:20:00', -1503, 'CODE1' ], ....] 

Here is the error I get in the console :

(node:37125) UnhandledPromiseRejectionWarning: Error: (conn=822, no: 1241, SQLState: 21000) Operand should contain 1 column(s) sql: INSERT INTO data_sycomore (date, valeur, codePS) VALUES (?) - parameters:[2019-04-01 00:00:00,-9017,CODE1,2019-04-01 00:10:00,-7381,CODE1,2019-04-01 00:20:00,-5798,CODE1,2019-04-01 00:30:00,-7594,CODE1,2019-04-01 00:40:00,-7011,CODE1,2019-04-01 00:50:...]     at Object.module.exports.createError (x/node_modules/mariadb/lib/misc/errors.js:55:10)     at PacketNodeEncoded.readError (x/node_modules/mariadb/lib/io/packet.js:523:19)     at Query.readResponsePacket (x/node_modules/mariadb/lib/cmd/resultset.js:46:28)     at PacketInputStream.receivePacketBasic (x/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)     at PacketInputStream.onData (x/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)     at Socket.emit (events.js:315:20)     at addChunk (_stream_readable.js:295:12)     at readableAddChunk (_stream_readable.js:271:9)     at Socket.Readable.push (_stream_readable.js:212:10)     at TCP.onStreamRead (internal/stream_base_commons.js:186:23) (node:37125) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:37125) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.