mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 23:27:12 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
ab0a7bbb13
20 changed files with 200 additions and 376 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { ClickHouse } from 'clickhouse';
|
||||
import { ClickHouseClient, createClient } from '@clickhouse/client';
|
||||
import dateFormat from 'dateformat';
|
||||
import debug from 'debug';
|
||||
import { CLICKHOUSE } from 'lib/db';
|
||||
|
|
@ -17,7 +17,7 @@ export const CLICKHOUSE_DATE_FORMATS = {
|
|||
|
||||
const log = debug('umami:clickhouse');
|
||||
|
||||
let clickhouse: ClickHouse;
|
||||
let clickhouse: ClickHouseClient;
|
||||
const enabled = Boolean(process.env.CLICKHOUSE_URL);
|
||||
|
||||
function getClient() {
|
||||
|
|
@ -25,18 +25,16 @@ function getClient() {
|
|||
hostname,
|
||||
port,
|
||||
pathname,
|
||||
protocol,
|
||||
username = 'default',
|
||||
password,
|
||||
} = new URL(process.env.CLICKHOUSE_URL);
|
||||
|
||||
const client = new ClickHouse({
|
||||
url: hostname,
|
||||
port: Number(port),
|
||||
format: 'json',
|
||||
config: {
|
||||
database: pathname.replace('/', ''),
|
||||
},
|
||||
basicAuth: password ? { username, password } : null,
|
||||
const client = createClient({
|
||||
host: `${protocol}//${hostname}:${port}`,
|
||||
database: pathname.replace('/', ''),
|
||||
username: username,
|
||||
password,
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
|
|
@ -118,7 +116,7 @@ async function parseFilters(websiteId: string, filters: QueryFilters = {}, optio
|
|||
};
|
||||
}
|
||||
|
||||
async function rawQuery<T>(query: string, params: object = {}): Promise<T> {
|
||||
async function rawQuery(query: string, params: Record<string, unknown> = {}): Promise<unknown> {
|
||||
if (process.env.LOG_QUERY) {
|
||||
log('QUERY:\n', query);
|
||||
log('PARAMETERS:\n', params);
|
||||
|
|
@ -126,7 +124,15 @@ async function rawQuery<T>(query: string, params: object = {}): Promise<T> {
|
|||
|
||||
await connect();
|
||||
|
||||
return clickhouse.query(query, { params }).toPromise() as Promise<T>;
|
||||
const resultSet = await clickhouse.query({
|
||||
query: query,
|
||||
query_params: params,
|
||||
format: 'JSONEachRow',
|
||||
});
|
||||
|
||||
const data = await resultSet.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async function findUnique(data) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ export function getDatabaseType(url = process.env.DATABASE_URL) {
|
|||
return POSTGRESQL;
|
||||
}
|
||||
|
||||
if (process.env.CLICKHOUSE_URL) {
|
||||
return CLICKHOUSE;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue