小编Rap*_*iro的帖子

当需要检查 jsonb 列中是否存在某个键时,如何使用 Sequelize 中的 queryInterface.bulkUpdate?

我想使用 Sequelize 迁移来更新 Postgres 数据库中的表。

我的 SQL 查询使用?Postgres 中的 de 运算符来处理 JSONB 列。

我需要运行的 SQL 查询是:

UPDATE messages SET type = 'products' WHERE type = 'gallery' and content ? '%textMain%'
Run Code Online (Sandbox Code Playgroud)

我在 Sequelize 中的迁移如下所示:

'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.bulkUpdate(
      'messages', 
      { type: 'products' }, 
      // HERE GOES THE WHERE CLAUSE
    )
  },

  down: async (_queryInterface, _Sequelize) => {
  }
};
Run Code Online (Sandbox Code Playgroud)

postgresql node.js sequelize.js

3
推荐指数
1
解决办法
3169
查看次数

标签 统计

node.js ×1

postgresql ×1

sequelize.js ×1