loopbackio / loopbackio/loopback-connector-postgresql

Support for overlaps json operator

Abierto
#570 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature
Lenguaje dominante
JavaScript
Estrellas
118
Forks
184
Merge medio
1 d 22 h
PR fusionados (30 d)
5

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el manejo existente de operadores de arrays cerca de la línea 553 de lib/postgresql.js y los casos relacionados en test/postgresql.test.js. Añade cobertura para las intersecciones en las que filter usa el ejemplo del issue y, después, actualiza la documentación de operadores alrededor de la línea 601 de README.md. Se considera terminado cuando el test pasa y el comportamiento de intersección de arrays de PostgreSQL está documentado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, postgresql
Área
databases
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
55/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.