mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Add connect methods to libraries.
This commit is contained in:
parent
186f484ff1
commit
e442617421
5 changed files with 59 additions and 28 deletions
|
|
@ -14,6 +14,9 @@ export const CLICKHOUSE_DATE_FORMATS = {
|
|||
|
||||
const log = debug('umami:clickhouse');
|
||||
|
||||
let clickhouse;
|
||||
const enabled = Boolean(process.env.CLICKHOUSE_URL);
|
||||
|
||||
function getClient() {
|
||||
const {
|
||||
hostname,
|
||||
|
|
@ -144,6 +147,8 @@ async function rawQuery(query, params = []) {
|
|||
log(formattedQuery);
|
||||
}
|
||||
|
||||
await connect();
|
||||
|
||||
return clickhouse.query(formattedQuery).toPromise();
|
||||
}
|
||||
|
||||
|
|
@ -159,12 +164,19 @@ async function findFirst(data) {
|
|||
return data[0] ?? null;
|
||||
}
|
||||
|
||||
// Initialization
|
||||
const clickhouse = process.env.CLICKHOUSE_URL && (global[CLICKHOUSE] || getClient());
|
||||
async function connect() {
|
||||
if (!clickhouse) {
|
||||
clickhouse = process.env.CLICKHOUSE_URL && (global[CLICKHOUSE] || getClient());
|
||||
}
|
||||
|
||||
return clickhouse;
|
||||
}
|
||||
|
||||
export default {
|
||||
enabled,
|
||||
client: clickhouse,
|
||||
log,
|
||||
connect,
|
||||
getDateStringQuery,
|
||||
getDateQuery,
|
||||
getDateFormat,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue