Skip to content
Snippets Groups Projects

feat: string length support

Open Leonardo Christino requested to merge feat/strlength into main
1 file
+ 27
24
Compare changes
  • Side-by-side
  • Inline
import { type AnyStatement } from 'ts-common/src/model/query/logic/general';
import { NumberAggregationTypes } from 'ts-common/src/model/query/logic/number';
import { StringFilterTypes, StringFunctionTypes } from 'ts-common/src/model/query/logic/string';
import type { QueryCacheData } from './model';
export function createWhereLogic(
@@ -30,24 +32,24 @@ export function extractLogicCypher(logicQuery: AnyStatement, cacheData: QueryCac
switch (typeof logicQuery) {
case 'object':
if (Array.isArray(logicQuery)) {
let op = logicQuery[0].replace('_', '').toLowerCase();
const op = logicQuery[0];
let newOp = op.replace('_', '').toLowerCase();
const right = logicQuery?.[2];
const { logic: left, where: whereLogic } = extractLogicCypher(logicQuery[1], cacheData);
switch (op) {
case '!=':
op = '<>';
newOp = '<>';
break;
case '==':
if (right === '".*"') op = '=~'; // in case "equals to <empty string>", this is what happens
else op = '=';
if (right === '".*"') newOp = '=~'; // in case "equals to <empty string>", this is what happens
else newOp = '=';
break;
case 'like':
op = '=~';
case StringFilterTypes.LIKE:
newOp = '=~';
break;
case 'in':
case 'present in list':
op = 'IN';
case StringFilterTypes.IN:
newOp = 'IN';
if (typeof right === 'string') {
return {
logic: `(${left} IN [${right
@@ -59,9 +61,8 @@ export function extractLogicCypher(logicQuery: AnyStatement, cacheData: QueryCac
};
}
break;
case 'not in':
case 'not in list':
op = 'NOT IN';
case StringFilterTypes.NOT_IN:
newOp = 'NOT IN';
if (typeof right === 'string') {
return {
logic: `(NOT ${left} IN [${right
@@ -73,19 +74,21 @@ export function extractLogicCypher(logicQuery: AnyStatement, cacheData: QueryCac
};
}
break;
case 'isempty':
case StringFilterTypes.EMPTY:
return { logic: `(${left} IS NULL OR ${left} = "")`, where: whereLogic };
case 'isnotempty':
case StringFilterTypes.NOT_EMPTY:
return { logic: `(${left} IS NOT NULL AND ${left} <> "")`, where: whereLogic };
case 'lower':
case StringFunctionTypes.LOWER:
return { logic: `toLower(${left})`, where: whereLogic };
case 'upper':
case StringFunctionTypes.UPPER:
return { logic: `toUpper(${left})`, where: whereLogic };
case 'avg':
case 'count':
case 'max':
case 'min':
case 'sum':
case StringFunctionTypes.LENGTH:
return { logic: `size(${left})`, where: whereLogic };
case NumberAggregationTypes.AVG:
case NumberAggregationTypes.COUNT:
case NumberAggregationTypes.MAX:
case NumberAggregationTypes.MIN:
case NumberAggregationTypes.SUM:
return createWhereLogic(op, left, whereLogic, cacheData);
}
if (logicQuery.length > 2 && logicQuery[2]) {
@@ -95,12 +98,12 @@ export function extractLogicCypher(logicQuery: AnyStatement, cacheData: QueryCac
for (const where of whereLogicRight) {
whereLogic.add(where);
}
if (op === '=~') {
if (newOp === '=~') {
rightMutable = `(".*" + ${rightMutable} + ".*")`;
}
return { logic: `(${left} ${op} ${rightMutable})`, where: whereLogic };
return { logic: `(${left} ${newOp} ${rightMutable})`, where: whereLogic };
}
return { logic: `(${op} ${left})`, where: whereLogic };
return { logic: `(${newOp} ${left})`, where: whereLogic };
}
return { logic: logicQuery, where: new Set() };
case 'string':
Loading