node.js - 有没有办法在 Sequelize.js 中包含包含在 JSONB 中的属性?

标签 node.js postgresql sequelize.js

下面 SQL 语句中的第二列从 JSONB 列 (entity_json) 中检索 Platform__c 属性。

当我尝试使用语法 ["account_name", "entity_json ->> 'Platform__c'"] 作为列名时,它失败了。出现此错误:"column \"entity_json ->> 'Platform__c'\" does not exist"
在 Sequelize.js 中有没有办法使用文档中突出显示的一些语法来检索此列?

SELECT "account_name", entity_json ->> 'Platform__c' test 
FROM "sfdc"."mt_account" AS "Account" WHERE "Account"."account_name" ILIKE
'somecustomer' LIMIT 10;

最佳答案

我现在在 Sequelize 4.44.0 上遇到了同样的问题,但是对我有用的是这样的:

Account.findAll({
  where: {
    name: {
      [Op.iLike]: 'somecustomer',
    },
  attributes: [
    'id',
    [sequelize.json('entity_json.Platform__c'), 'Platform__c']
  ],
});

希望能帮助到你。

关于node.js - 有没有办法在 Sequelize.js 中包含包含在 JSONB 中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36873019/

相关文章:

node.js - Express.js req.body 未定义

数据库设计 - 两个项目应该共享同一个表吗?

python - Django 缓存导致数据库中出现重复键错误?

javascript - Node.js Sequelize ManyToMany 关系产生不正确的 SQL

sequelize.js - 复杂的销毁查询

javascript - 如何将混合表更改为 Sequelize?

javascript - 错误 : Still Getting Error after setting allowLargeResults to true in job configuration?

node.js - 在nodejs中使用pdfkit创建pdf文件

javascript - 如何在 ShellJS 命令执行期间运行 cli-spinner?

node.js - 如何在 Sequelize 中正确配置和计算belongsToMany 关联?