loopbackio / loopbackio/loopback-connector-postgresql

Support for overlaps json operator

オープン
#570 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature
主要言語
JavaScript
スター
118
フォーク
184
平均マージ
1日 22時間
マージ済み PR(30日)
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。