From 2257ad7b709d39d2dba1478f5c1c0f1ccd0a44d3 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Mon, 3 Jul 2023 17:05:51 +0100 Subject: [PATCH] Allow * as wildcard in filter, re #2070 No UI but edit the URL to provide a filter with * in it and the query gets changed to LIKE and the * to %. Works in MySQL at least! fix regex --- lib/prisma.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/prisma.ts b/lib/prisma.ts index 0a10d9816..17638928b 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -111,9 +111,16 @@ function getFilterQuery(filters = {}, params = []): string { const filter = filters[key]; if (filter !== undefined) { + let filterValue = decodeURIComponent(filter), + op = '='; const column = FILTER_COLUMNS[key] || key; - arr.push(`and ${column}=$${params.length + 1}`); - params.push(decodeURIComponent(filter)); + + if (filterValue.indexOf('*') > -1) { + op = 'LIKE'; + filterValue = filterValue.replaceAll(/\*+/g, '%'); + } + arr.push(`and ${column} ${op} $${params.length + 1}`); + params.push(filterValue); } return arr;