我正在尝试过滤jsonb
我的应用程序中的列,loopback
但无法过滤。
这是我的模型:
import {Entity, model, property} from '@loopback/repository';
@model({
settings: {idInjection: false, postgresql: {schema: 'public', table: 'sampletable'}}
})
export class SampleModel extends Entity {
@property({
type: 'number',
required: true,
hidden: true,
scale: 0,
id: 1,
postgresql: {columnName: 'id', dataType: 'bigint', dataLength: null, dataPrecision: null, dataScale: 0, nullable: 'NO'},
})
id: number;
@property({
type: 'number',
required: true,
scale: 0,
postgresql: {columnName: 'code', dataType: 'integer', dataLength: null, dataPrecision: null, dataScale: 0, nullable: 'NO'},
})
code: number;
@property({
type: 'string',
postgresql: {columnName: 'guide', dataType: 'text', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES'},
})
guide?: string;
@property({
type: 'Object',
postgresql: {columnName: 'grade_data', dataType: 'jsonb', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES'},
})
gradeData?: Object;
// Define well-known properties here
// Indexer property to allow additional data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[prop: string]: any;
constructor(data?: Partial<SampleModel>) {
super(data);
}
}
export interface SampleModelRelations {
// describe navigational properties here
}
export type SampleModelWithRelations = SampleModel & SampleModelRelations;
这是带有示例行的表:
例如:
ID | 代码 | 指导 | 等级数据 |
---|---|---|---|
1 | 12345 | 2021 年指南 | {"en":"Eng Grade","de":"Ger Grade"} |
- 我可以
where
用于过滤jsonb
列中的数据吗?例如:过滤代码 = 12345 将是
{
"where": {
"code": 4950010
}
}
如果我想搜索,类似的过滤器会是什么grade_data ->> 'en'
?
- 我可以使用仅在列数据
include
中包含某些键吗?jsonb
例如:过滤器只包含代码将是
{
"fields": {
"code": true
}
}
如果我只想检索,类似的过滤器会是什么grade_data ->> 'en'
?