I have an array
newData = [{ sId: 'XXXXXX', itemlName: 'LSストレッ', iCode: 'XXXXXX', iType: '', skus: 'XXXXXXX', iLevel: 'L2', cCode: '88', cName: 'Other', sCode: '999', sName: 'No Control', pLengthCode: '988', core: 'N', sCode: '1', dCode: 'XX', gDeptCode: 'XX', gDeptName: 'Women\\\'s Items', rCode: 'jqs' },{ sId: 'XXXXXX', itemlName: 'LSストレッ', iCode: 'XXXXXX', iType: '', skus: 'XXXXXXX', iLevel: 'L2', cCode: '88', cName: 'Other', sCode: '999', sName: 'No Control', pLengthCode: '988', core: 'N', sCode: '1', dCode: 'XX', gDeptCode: 'XX', gDeptName: 'Women\\\'s Items', rCode: 'jqs' }]
I wants to insert newData
in to mysql database using objection.js. But when I run my node application , I got the error saying:
Error: batch insert only works with Postgresql
My insert code is -:
samplemodel.query().insert( newData );
How can I perform the batch insertion of array data in mysql data base using objection.js?
Error: batch insert only works with Postgresql
Well, that means that you need Postgres's instead of Mysql to make it work.
Edit1:
From the docs:
If you are using Postgres the inserts are done in batches for maximum performance. On other databases the rows need to be inserted one at a time. This is because postgresql is the only database engine that returns the identifiers of all inserted rows and not just the first or the last one.
That means that if you are using mysql you should do
samplemodel.query().insert(data);
For each element in the "newData" array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With