Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add.ilike.operator #374

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/utils/operators.ts
Original file line number Diff line number Diff line change
@@ -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: "=",
Expand All @@ -9,6 +9,7 @@ export const KnexOperators = {
ge: ">=",
like: "like",
nlike: "not like",
ilike: "ilike",
in: "in",
nin: "not in",
};
Expand Down Expand Up @@ -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: <T = any>(actual: T, expected: T[]) => expected.includes(actual),
nin: <T = any>(actual: T, expected: T[]) => !expected.includes(actual),
};
Loading