我想使用Sequelize迁移来更新我的Postgres数据库中的一个表。
我的SQL查询使用Postgres中的de?
操作符来查询JSONB列。
UPDATE messages SET type = 'products' WHERE type = 'gallery' and content ? '%textMain%'
我在Sequelize中的迁移是这样的:
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkUpdate(
'messages',
{ type: 'products' },
// HERE GOES THE WHERE CLAUSE
)
},
down: async (_queryInterface, _Sequelize) => {
}
};
在失去一些头发后寻找答案。
我是这样解决的:
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.bulkUpdate(
'messages',
{ type: 'products' },
Sequelize.literal("type = 'gallery' AND content ? 'textMain'")
)
},
down: async (_queryInterface, _Sequelize) => {
}
};
希望能帮助到有同样问题的人!: + 1
我希望看到其他的方法来解决这个问题。