环回 3 是否支持 table 的 JSON 字段上的过滤器?我正在使用 MySQL 数据库
Does loopback 3 support filters on JSON field of a table ? I am using MySQL database
环回 3 是否支持 table 的 JSON 字段上的过滤器?我正在使用 MySQL 数据库。
比如我们创建table'events'-
创建 TABLE 个事件(
id int auto_increment 主键,
event_name varchar(255),
访客 varchar(255),
属性 json,
浏览器 json
);
有什么方法可以在 json 字段 'properties' 和 'browser' 上应用过滤器吗?
首先,MySQL 不索引 JSON 列(有解决方法,但本机不支持),如果你使用 MySQL,它可能是问题附近的功能。
它认为这是不可能的,因为 doc 说:
Data source connectors for relational databases don’t support filtering nested properties.
但是,您可以通过使用操作挂钩为内置方法实现自己的逻辑。
例如
Model - the constructor of the model that will be queried
query - the query containing fields where, include, order, etc.
MyModel.observe('access', function **queryToJsonField**(ctx, next) {
// operation goes here
next();
});
更详细的解释可以在doc
找到
环回 3 是否支持 table 的 JSON 字段上的过滤器?我正在使用 MySQL 数据库。
比如我们创建table'events'- 创建 TABLE 个事件( id int auto_increment 主键, event_name varchar(255), 访客 varchar(255), 属性 json, 浏览器 json );
有什么方法可以在 json 字段 'properties' 和 'browser' 上应用过滤器吗?
首先,MySQL 不索引 JSON 列(有解决方法,但本机不支持),如果你使用 MySQL,它可能是问题附近的功能。
它认为这是不可能的,因为 doc 说:
Data source connectors for relational databases don’t support filtering nested properties.
但是,您可以通过使用操作挂钩为内置方法实现自己的逻辑。
例如
Model - the constructor of the model that will be queried query - the query containing fields where, include, order, etc. MyModel.observe('access', function **queryToJsonField**(ctx, next) { // operation goes here next(); });
更详细的解释可以在doc
找到