mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Use next-basics package.
This commit is contained in:
parent
1a6af8fc41
commit
f4e0da481e
62 changed files with 255 additions and 373 deletions
|
|
@ -12,13 +12,9 @@ export const CLICKHOUSE_DATE_FORMATS = {
|
|||
year: '%Y-01-01',
|
||||
};
|
||||
|
||||
const log = debug('clickhouse');
|
||||
const log = debug('umami:clickhouse');
|
||||
|
||||
function getClient() {
|
||||
if (!process.env.CLICKHOUSE_URL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
hostname,
|
||||
port,
|
||||
|
|
@ -149,13 +145,13 @@ function parseFilters(table, column, filters = {}, params = [], sessionKey = 'se
|
|||
};
|
||||
}
|
||||
|
||||
function replaceQuery(string, params = []) {
|
||||
let formattedString = string;
|
||||
function formatQuery(str, params = []) {
|
||||
let formattedString = str;
|
||||
|
||||
params.forEach((a, i) => {
|
||||
let replace = a;
|
||||
params.forEach((param, i) => {
|
||||
let replace = param;
|
||||
|
||||
if (typeof a === 'string' || a instanceof String) {
|
||||
if (typeof param === 'string' || param instanceof String) {
|
||||
replace = `'${replace}'`;
|
||||
}
|
||||
|
||||
|
|
@ -165,11 +161,11 @@ function replaceQuery(string, params = []) {
|
|||
return formattedString;
|
||||
}
|
||||
|
||||
async function rawQuery(query, params = [], debug = false) {
|
||||
let formattedQuery = replaceQuery(query, params);
|
||||
async function rawQuery(query, params = []) {
|
||||
let formattedQuery = formatQuery(query, params);
|
||||
|
||||
if (debug || process.env.LOG_QUERY) {
|
||||
console.log(formattedQuery);
|
||||
if (process.env.LOG_QUERY) {
|
||||
log(formattedQuery);
|
||||
}
|
||||
|
||||
return clickhouse.query(formattedQuery).toPromise();
|
||||
|
|
@ -188,7 +184,7 @@ async function findFirst(data) {
|
|||
}
|
||||
|
||||
// Initialization
|
||||
const clickhouse = global[CLICKHOUSE] || getClient();
|
||||
const clickhouse = process.env.CLICKHOUSE_URL && (global[CLICKHOUSE] || getClient());
|
||||
|
||||
export default {
|
||||
client: clickhouse,
|
||||
|
|
@ -199,8 +195,7 @@ export default {
|
|||
getBetweenDates,
|
||||
getFilterQuery,
|
||||
parseFilters,
|
||||
replaceQuery,
|
||||
rawQuery,
|
||||
findUnique,
|
||||
findFirst,
|
||||
rawQuery,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue