Adding $nor operator support (#4768)

* adding nor to specialQuerykeys

* adding nor suport

* adding test

* CRLF

* adding postgres NOR

* adding nor validation

* adding NOR test

* adding test amd fixing NOR cases

* revert the nor logic
This commit is contained in:
Jérémy Piednoel
2018-05-18 15:26:33 -04:00
committed by Diamond Lewis
parent a9ebc2b9af
commit 77ed10f57b
4 changed files with 74 additions and 6 deletions

View File

@@ -306,7 +306,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
patterns.push(`$${index}:name = $${index + 1}`);
values.push(fieldName, fieldValue);
index += 2;
} else if (fieldName === '$or' || fieldName === '$and') {
} else if (['$or', '$nor', '$and'].includes(fieldName)) {
const clauses = [];
const clauseValues = [];
fieldValue.forEach((subQuery) => {
@@ -317,8 +317,11 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
index += clause.values.length;
}
});
const orOrAnd = fieldName === '$or' ? ' OR ' : ' AND ';
patterns.push(`(${clauses.join(orOrAnd)})`);
const orOrAnd = fieldName === '$and' ? ' AND ' : ' OR ';
const not = fieldName === '$nor' ? ' NOT ' : '';
patterns.push(`${not}(${clauses.join(orOrAnd)})`);
values.push(...clauseValues);
}