From 05335854f15932af5ffaf3930b244cf8dfe8692b Mon Sep 17 00:00:00 2001 From: Martin Arbez Date: Fri, 22 Dec 2023 13:09:59 -0300 Subject: [PATCH] feat/add.ilike.operator --- src/utils/operators.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/utils/operators.ts b/src/utils/operators.ts index 12b4a52..b8c7dcc 100644 --- a/src/utils/operators.ts +++ b/src/utils/operators.ts @@ -1,4 +1,4 @@ -export type OperatorName = "eq" | "ne" | "lt" | "gt" | "le" | "ge" | "like" | "nlike" | "in" | "nin"; +export type OperatorName = "eq" | "ne" | "lt" | "gt" | "le" | "ge" | "like" | "nlike" | "ilike"| "in" | "nin"; export const KnexOperators = { eq: "=", @@ -9,6 +9,7 @@ export const KnexOperators = { ge: ">=", like: "like", nlike: "not like", + ilike: "ilike", in: "in", nin: "not in", }; @@ -50,6 +51,21 @@ export const FunctionalOperators: { [T in OperatorName]: (actual: any, expected: return false; }, + ilike: (actual: string, expected: string) => { + if (expected.startsWith("%") && expected.endsWith("%")) { + return actual.includes(expected.replace(/%/g, "")); + } + + if (expected.startsWith("%")) { + return actual.endsWith(expected.replace(/%/g, "")); + } + + if (expected.endsWith("%")) { + return actual.startsWith(expected.replace(/%/g, "")); + } + + return false; + }, in: (actual: T, expected: T[]) => expected.includes(actual), nin: (actual: T, expected: T[]) => !expected.includes(actual), };