我有一个数组
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' }]
我想使用 objection.js 将 newData
插入到 mysql 数据库中。但是当我运行我的 Node 应用程序时,我收到错误消息:
Error: batch insert only works with Postgresql
我的插入代码是-:
samplemodel.query().insert( newData );
如何使用objection.js批量插入mysql数据库中的数组数据?
最佳答案
错误:批量插入只适用于 Postgresql
好吧,这意味着您需要 Postgres 而不是 Mysql 才能使其工作。
编辑1:
来自文档:
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.
这意味着如果你正在使用 mysql 你应该这样做
samplemodel.query().insert(data);
对于“newData”数组中的每个元素。
关于mysql - 使用 objection.js 将数组数据批量插入到 mysql 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37786828/