feat(core): Add support for like match filters (no-changelog) (#18755)

This commit is contained in:
Daria
2025-08-26 17:03:00 +03:00
committed by GitHub
parent d892574989
commit 46432da41b
7 changed files with 808 additions and 2 deletions

View File

@@ -261,3 +261,29 @@ export function normalizeValue(
return value;
}
/**
* Convert a LIKE-style pattern (only % is wildcard) into a SQLite GLOB pattern.
*/
export function toSqliteGlobFromPercent(input: string): string {
const out: string[] = [];
for (const ch of String(input ?? '')) {
if (ch === '%') out.push('*');
else if (ch === '[') out.push('[[]');
else if (ch === ']') out.push('[]]');
else if (ch === '*') out.push('[*]');
else if (ch === '?') out.push('[?]');
else out.push(ch);
}
return out.join('');
}
/**
* LIKE escaper for DBs where we use ESCAPE '\'.
* Keep '%' as wildcard; make '_' literal; escape the escape char itself.
*/
export function escapeLikeSpecials(input: string): string {
return input
.replace(/\\/g, '\\\\') // escape the escape char itself
.replace(/_/g, '\\_'); // make '_' literal ('%' stays a wildcard)
}