mysql - 使用 objection.js 将数组数据批量插入到 mysql 数据库中

标签 mysql node.js knex.js objection.js

我有一个数组

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/

相关文章:

node.js - 作为守护进程运行的带有 redis 的 Docker 容器不运行

node.js - MySQL knex 数学运算

php - 我可以安全地使用带有 utf8 列的 utf8mb4 连接吗?

mysql - 通过 MySQL 查询插入 Symfony NestedSet 数据

node.js - HTML 通过电子邮件发送标签

javascript - 登录后无法获取和检索用户数据

arrays - 字符串数组迁移的语法

node.js - Bookshelf.js/Knex.js 上数据库模式加载的常见做法

php - 使用表连接与 2 个 MySQL 表和 DISTINCT 获取信息

php - 奇怪的字符,例如