为 postgresQL 续写 bulkCreate updateOnDuplicate?
Sequelize bulkCreate updateOnDuplicate for postgresQL?
我知道 Sequelize sequelize doc 不支持 postgresQL 的 updateOnDuplicate,所以有解决办法吗?
是否可以通过"SQL command"实现。
有一些解决方法。参见 upsert function. When used in Postgresql it creates custom function in database. Unfortunately there is no bulkUpsert
, so you either use it in some for-loop or execute raw SQL as suggested 。
新的 sequelize (v5) 包含适用于所有方言的 updateOnDuplicate 功能
Fields to update if row key already exists (on duplicate key update)?
(only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >=
9.5). By default, all fields are updated.
在这里查看:Docs
您可以用作
model.bulkCreate(dataToUpdate, { updateOnDuplicate: ["user_id", "token", "created_at"] })
我知道 Sequelize sequelize doc 不支持 postgresQL 的 updateOnDuplicate,所以有解决办法吗?
是否可以通过"SQL command"实现。
有一些解决方法。参见 upsert function. When used in Postgresql it creates custom function in database. Unfortunately there is no bulkUpsert
, so you either use it in some for-loop or execute raw SQL as suggested
新的 sequelize (v5) 包含适用于所有方言的 updateOnDuplicate 功能
Fields to update if row key already exists (on duplicate key update)? (only supported by MySQL, MariaDB, SQLite >= 3.24.0 & Postgres >= 9.5). By default, all fields are updated.
在这里查看:Docs
您可以用作
model.bulkCreate(dataToUpdate, { updateOnDuplicate: ["user_id", "token", "created_at"] })