Merge branch 'fix-4123' of https://github.com/ElfenB/umami into ElfenB-fix-4123
This commit is contained in:
commit
0fff8fbb86
2 files changed
+38
-7
No files matched your search
+17
-3
@@ -1,7 +1,7 @@
|
|||||||
import { CLICKHOUSE } from '@/lib/db';
|
|
||||||
import { type ClickHouseClient, createClient } from '@clickhouse/client';
|
import { type ClickHouseClient, createClient } from '@clickhouse/client';
|
||||||
import { formatInTimeZone } from 'date-fns-tz';
|
import { formatInTimeZone } from 'date-fns-tz';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
import { CLICKHOUSE } from '@/lib/db';
|
||||||
import { DATA_TYPE, DEFAULT_PAGE_SIZE, FILTER_COLUMNS, OPERATORS } from './constants';
|
import { DATA_TYPE, DEFAULT_PAGE_SIZE, FILTER_COLUMNS, OPERATORS } from './constants';
|
||||||
import { filtersObjectToArray } from './params';
|
import { filtersObjectToArray } from './params';
|
||||||
import type { Operator, PropertyFilter, QueryFilters, QueryOptions } from './types';
|
import type { Operator, PropertyFilter, QueryFilters, QueryOptions } from './types';
|
||||||
@@ -79,7 +79,13 @@ function getSearchSQL(column: string, param: string = 'search'): string {
|
|||||||
return `and positionCaseInsensitive(${column}, {${param}:String}) > 0`;
|
return `and positionCaseInsensitive(${column}, {${param}:String}) > 0`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapFilter(column: string, operator: Operator, name: string, type: string = 'String', paramName?: string) {
|
function mapFilter(
|
||||||
|
column: string,
|
||||||
|
operator: Operator,
|
||||||
|
name: string,
|
||||||
|
type: string = 'String',
|
||||||
|
paramName?: string,
|
||||||
|
) {
|
||||||
const param = paramName ?? name;
|
const param = paramName ?? name;
|
||||||
const value = `{${param}:${type}}`;
|
const value = `{${param}:${type}}`;
|
||||||
|
|
||||||
@@ -388,7 +394,15 @@ async function pagedRawQuery(
|
|||||||
const count = await rawQuery(countQuery, queryParams).then(res => res[0].num);
|
const count = await rawQuery(countQuery, queryParams).then(res => res[0].num);
|
||||||
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
||||||
|
|
||||||
return { data, count, page: +page, pageSize: size, orderBy, search, isCapped: !!maxResults && +count >= +maxResults };
|
return {
|
||||||
|
data,
|
||||||
|
count,
|
||||||
|
page: +page,
|
||||||
|
pageSize: size,
|
||||||
|
orderBy,
|
||||||
|
search,
|
||||||
|
isCapped: !!maxResults && +count >= +maxResults,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rawQuery<T = unknown>(
|
async function rawQuery<T = unknown>(
|
||||||
|
|||||||
+21
-4
@@ -1,8 +1,14 @@
|
|||||||
import { PrismaClient } from '@/generated/prisma/client';
|
|
||||||
import { PrismaPg } from '@prisma/adapter-pg';
|
import { PrismaPg } from '@prisma/adapter-pg';
|
||||||
import { readReplicas } from '@prisma/extension-read-replicas';
|
import { readReplicas } from '@prisma/extension-read-replicas';
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
import { DATA_TYPE, DEFAULT_PAGE_SIZE, FILTER_COLUMNS, OPERATORS, SESSION_COLUMNS } from './constants';
|
import { PrismaClient } from '@/generated/prisma/client';
|
||||||
|
import {
|
||||||
|
DATA_TYPE,
|
||||||
|
DEFAULT_PAGE_SIZE,
|
||||||
|
FILTER_COLUMNS,
|
||||||
|
OPERATORS,
|
||||||
|
SESSION_COLUMNS,
|
||||||
|
} from './constants';
|
||||||
import { filtersObjectToArray } from './params';
|
import { filtersObjectToArray } from './params';
|
||||||
import type { Operator, PropertyFilter, QueryFilters, QueryOptions } from './types';
|
import type { Operator, PropertyFilter, QueryFilters, QueryOptions } from './types';
|
||||||
|
|
||||||
@@ -68,7 +74,11 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {
|
|||||||
return `to_char(date_trunc('${unit}', ${field}), '${DATE_FORMATS_UTC[unit]}')`;
|
return `to_char(date_trunc('${unit}', ${field}), '${DATE_FORMATS_UTC[unit]}')`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDateStringSQL(field: string, unit: keyof typeof DATE_STRING_FORMATS = 'utc', timezone?: string): string {
|
function getDateStringSQL(
|
||||||
|
field: string,
|
||||||
|
unit: keyof typeof DATE_STRING_FORMATS = 'utc',
|
||||||
|
timezone?: string,
|
||||||
|
): string {
|
||||||
if (timezone && !isUtcTimezone(timezone)) {
|
if (timezone && !isUtcTimezone(timezone)) {
|
||||||
return `to_char(${field} at time zone '${timezone}', '${DATE_STRING_FORMATS[unit]}')`;
|
return `to_char(${field} at time zone '${timezone}', '${DATE_STRING_FORMATS[unit]}')`;
|
||||||
}
|
}
|
||||||
@@ -478,7 +488,14 @@ async function pagedRawQuery(
|
|||||||
const count = await rawQuery(countQuery, queryParams).then(res => Number(res[0].num));
|
const count = await rawQuery(countQuery, queryParams).then(res => Number(res[0].num));
|
||||||
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
||||||
|
|
||||||
return { data, count, page: +page, pageSize: size, orderBy, isCapped: !!maxResults && +count >= +maxResults };
|
return {
|
||||||
|
data,
|
||||||
|
count,
|
||||||
|
page: +page,
|
||||||
|
pageSize: size,
|
||||||
|
orderBy,
|
||||||
|
isCapped: !!maxResults && +count >= +maxResults,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSearchParameters(query: string, filters: Record<string, any>[]) {
|
function getSearchParameters(query: string, filters: Record<string, any>[]) {
|
||||||
|
|||||||
Reference in new issue
Block a user