【发布时间】:2021-10-03 08:46:33
【问题描述】:
我用knex在nodejs中写,我想更新db中的多行,我想知道我是否可以并行执行多个更新查询,
像这样:
const updatesPromises = books.map((book) =>
transaction('books')
.where({ id: book.id })
.update({ title: book.name }, ['id', 'title'])
await Promise.all(updatesPromises)
而是同步执行每个更新查询,如下所示:
books.forEach(async (book) =>
await transaction('books')
.where({ id: 42 })
.update({ title: "The Hitchhiker's Guide to the Galaxy" }, ['id', 'title'])
-
transaction是我之前创建的连接,在所有更新后提交
这是最佳做法吗?
会造成大规模的问题吗?
【问题讨论】:
-
Nodejs 这里没有使用多线程。
-
I/O 并行发生
标签: node.js typescript postgresql multithreading knex.js