Updated types.

This commit is contained in:
Mike Cao 2024-01-14 02:21:39 -08:00
parent 1e0c177fe6
commit 6b9c83381c
12 changed files with 40 additions and 43 deletions

View file

@ -46,22 +46,22 @@ function getClient() {
return client;
}
function getDateStringQuery(data, unit) {
function getDateStringQuery(data: any, unit: string | number) {
return `formatDateTime(${data}, '${CLICKHOUSE_DATE_FORMATS[unit]}')`;
}
function getDateQuery(field, unit, timezone?) {
function getDateQuery(field: string, unit: string, timezone?: string) {
if (timezone) {
return `date_trunc('${unit}', ${field}, '${timezone}')`;
}
return `date_trunc('${unit}', ${field})`;
}
function getDateFormat(date) {
function getDateFormat(date: Date) {
return `'${dateFormat(date, 'UTC:yyyy-mm-dd HH:MM:ss')}'`;
}
function mapFilter(column, operator, name, type = 'String') {
function mapFilter(column: string, operator: string, name: string, type = 'String') {
switch (operator) {
case OPERATORS.equals:
return `${column} = {${name}:${type}}`;
@ -130,12 +130,10 @@ async function rawQuery(query: string, params: Record<string, unknown> = {}): Pr
format: 'JSONEachRow',
});
const data = await resultSet.json();
return data;
return resultSet.json();
}
async function findUnique(data) {
async function findUnique(data: any[]) {
if (data.length > 1) {
throw `${data.length} records found when expecting 1.`;
}
@ -143,7 +141,7 @@ async function findUnique(data) {
return findFirst(data);
}
async function findFirst(data) {
async function findFirst(data: any[]) {
return data[0] ?? null;
}

View file

@ -206,16 +206,14 @@ function getPageFilters(filters: SearchFilter): [
];
}
function getSearchMode(): { mode?: Prisma.QueryMode } {
function getQueryMode(): Prisma.QueryMode {
const db = getDatabaseType();
if (db === POSTGRESQL) {
return {
mode: 'insensitive',
};
return 'insensitive';
}
return {};
return 'default';
}
export default {
@ -228,6 +226,6 @@ export default {
getFilterQuery,
parseFilters,
getPageFilters,
getSearchMode,
getQueryMode,
rawQuery,
};