loopbackio / loopbackio/loopback-connector-postgresql
Support for overlaps json operator
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 118
- 派生
- 184
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 5
描述
Suggestion
The connector support the "contains" json/array operator. This operator select rows which contain ALL value in the array.
I propose the support the "overlaps" json/array operator. This operator select rown which contain ANY value in the array.
Use Cases
With this feature, you will be able to use the JSON Array [array operator &&] operator from PostgreSQL(https://www.postgresql.org/docs/current/functions-array.html).
Examples
Row 1: [ A, B]
Row 2: [C, D]
Row 3: [E, A, B ]
Look for any row which overlaps with [C, F] => Should return Row 2
Acceptance criteria
- Doc
- Test
- Code
It is very easy to implement. Unfortunately, I don't know how to use correctly GitHub for PR. So, I can provide code, and i hope someone will be able to PR it.
/test/postgresql.test.js line 294 -------------
it('should support the "overlaps" where filter for array type field', async () => {
await Post.create({
title: 'Overlaps: LoopBack Participates in Hacktoberfest',
categories: ['OL_LoopBack', 'OL_Announcements'],
});
await Post.create({
title: 'Overlaps: Growing LoopBack Community',
categories: ['OL_LoopBack', 'OL_Community'],
});
const found = await Post.find({where: {and: [
{
categories: {'overlaps': ['OL_Super', 'OL_Community']},
},
]}});
found.map(p => p.title).should.deepEqual(['Overlaps: Growing LoopBack Community']);
});
/lib/postgresql.js, line 553 ------------------------------------------------------
case 'overlaps':
return new ParameterizedSQL(columnName + ' && array[' + operatorValue.map(() => '?') + ']::'
+ propertyDefinition.postgresql.dataType,
operatorValue);
case 'contains':
return new ParameterizedSQL(columnName + ' @> array[' + operatorValue.map(() => '?') + ']::'
+ propertyDefin
README.md line 601---------------------------------------------------
Operator overlaps
The overlaps operator allow you to query array properties and pick only
rows where the stored value contains any of the items specified by the query.
The operator is implemented using PostgreSQL array operator &&.
Note The fields you are querying must be setup to use the postgresql array data type - see Defining models above.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 lib/postgresql.js 第 553 行附近现有的数组运算符处理以及 test/postgresql.test.js 中的相关用例开始。使用 issue 中的示例,为 filter 时发生重叠的情况添加覆盖,然后更新 README.md 第 601 行附近的运算符文档。测试通过且 PostgreSQL 数组重叠行为已有文档说明,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, postgresql
- 领域
- databases
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100