This commit is contained in:
Mike Cao 2024-04-06 21:58:44 -07:00
commit 15a3cc2e1e
3 changed files with 11 additions and 5 deletions

View File

@ -93,6 +93,13 @@ function getTimestampDiffQuery(field1: string, field2: string): string {
}
}
function getSearchQuery(column: string): string {
const db = getDatabaseType();
const like = db === POSTGRESQL ? 'ilike' : 'like';
return `and ${column} ${like} {{search}}`;
}
function mapFilter(column: string, operator: string, name: string, type: string = '') {
const db = getDatabaseType();
const like = db === POSTGRESQL ? 'ilike' : 'like';
@ -253,6 +260,7 @@ export default {
getFilterQuery,
getSearchParameters,
getTimestampDiffQuery,
getSearchQuery,
getQueryMode,
pagedQuery,
parseFilters,

View File

@ -18,11 +18,11 @@ async function relationalQuery(
endDate: Date,
search: string,
) {
const { rawQuery } = prisma;
const { rawQuery, getSearchQuery } = prisma;
let searchQuery = '';
if (search) {
searchQuery = `and ${column} LIKE {{search}}`;
searchQuery = getSearchQuery(column);
}
return rawQuery(

View File

@ -43,10 +43,8 @@ async function relationalQuery(
min(website_event.created_at) as "min_time",
max(website_event.created_at) as "max_time"
from website_event
join website
on website_event.website_id = website.website_id
${joinSession}
where website.website_id = {{websiteId::uuid}}
where website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
and event_type = {{eventType}}
${filterQuery}