如何在 feathers/objections ORM 中查询 jsonb (postgtresql)?
How to query jsonb (postgtresql) in feathers/objections ORM?
我阅读了以下文档:https://github.com/feathersjs-ecosystem/feathers-objection
仍然无法查询 jsonb 列。
我的table包含:id,some_other_fields,分段:jsonb
细分列的值如下:
{"type": "WT", "group": "D", "style": 880, "design": 1, "subtype": "ABL"}
如何查询,例如 type = "WT"
?
Sql代码是:
select *
from products
where segmentation ->> 'type' = 'WT';
但是ORM代码:
const query = {
segmentation: {type:"WT"}
};
它不起作用。
我设法得到的是:Bad request.... "segmentation" = - invalid input syntax for type json
玩语法或根本没有结果。
有什么想法吗?
在引用列内的 json 属性时,您应该告诉 ORM 有异议:
.where({'segmentation:type' : 'WT'})
勾选
https://vincit.github.io/objection.js/recipes/json-queries.html
和
https://vincit.github.io/objection.js/api/types/#type-fieldexpression
万一其他人无意中发现了这个问题,答案是:
在 your_service_name.model.js
中,您必须声明 json 架构:
properties: {
your_jsonb_property: {type: 'object'}
}
Json 模式是可选的,但没有它就无法工作。
我阅读了以下文档:https://github.com/feathersjs-ecosystem/feathers-objection 仍然无法查询 jsonb 列。
我的table包含:id,some_other_fields,分段:jsonb 细分列的值如下:
{"type": "WT", "group": "D", "style": 880, "design": 1, "subtype": "ABL"}
如何查询,例如 type = "WT"
?
Sql代码是:
select *
from products
where segmentation ->> 'type' = 'WT';
但是ORM代码:
const query = {
segmentation: {type:"WT"}
};
它不起作用。
我设法得到的是:Bad request.... "segmentation" = - invalid input syntax for type json
玩语法或根本没有结果。
有什么想法吗?
在引用列内的 json 属性时,您应该告诉 ORM 有异议:
.where({'segmentation:type' : 'WT'})
勾选
https://vincit.github.io/objection.js/recipes/json-queries.html
和
https://vincit.github.io/objection.js/api/types/#type-fieldexpression
万一其他人无意中发现了这个问题,答案是:
在 your_service_name.model.js
中,您必须声明 json 架构:
properties: {
your_jsonb_property: {type: 'object'}
}
Json 模式是可选的,但没有它就无法工作。