loopbackio / loopbackio/loopback-connector-postgresql

Support for overlaps json operator

Offen
#570 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature
Vorherrschende Sprache
JavaScript
Sterne
118
Forks
184
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
5

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der bestehenden Behandlung von Array-Operatoren in der Nähe von Zeile 553 in lib/postgresql.js und den zugehörigen Fällen in test/postgresql.test.js. Füge Abdeckung für die Überschneidungen hinzu, bei denen filter das Beispiel aus dem Issue verwendet, und aktualisiere anschließend die Dokumentation der Operatoren um README.md, Zeile 601. Erledigt bedeutet, dass der Test erfolgreich ist und das Verhalten von PostgreSQL bei Array-Überschneidungen dokumentiert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, postgresql
Bereich
databases
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
55/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.