mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
fix CH return.
This commit is contained in:
parent
af7c6f73b0
commit
f189035a73
12
lib/db.js
12
lib/db.js
@ -277,14 +277,22 @@ export async function rawQueryClickhouse(query, params = [], debug = false) {
|
|||||||
return clickhouse.query(formattedQuery).toPromise();
|
return clickhouse.query(formattedQuery).toPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function findUnique(data) {
|
||||||
|
if (data.length > 1) {
|
||||||
|
throw `${data.length} records found when expecting 1.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
export async function runAnalyticsQuery(queries) {
|
export async function runAnalyticsQuery(queries) {
|
||||||
const db = getAnalyticsDatabase();
|
const db = getAnalyticsDatabase();
|
||||||
|
|
||||||
if (db === POSTGRESQL || db === MYSQL) {
|
if (db === POSTGRESQL || db === MYSQL) {
|
||||||
return queries[`${RELATIONAL}`]();
|
return queries[RELATIONAL]();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (db === CLICKHOUSE) {
|
if (db === CLICKHOUSE) {
|
||||||
return queries[`${CLICKHOUSE}`]();
|
return queries[CLICKHOUSE]();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ export async function getSession(req) {
|
|||||||
|
|
||||||
let session = await getSessionByUuid(session_uuid);
|
let session = await getSessionByUuid(session_uuid);
|
||||||
|
|
||||||
session = Array.isArray(session) && session[0] ? session[0] : session;
|
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
try {
|
try {
|
||||||
session = await createSession(website_id, {
|
session = await createSession(website_id, {
|
||||||
|
@ -11,8 +11,8 @@ import {
|
|||||||
|
|
||||||
export async function getEventMetrics(...args) {
|
export async function getEventMetrics(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export function getEvents(...args) {
|
export function getEvents(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function saveEvent(...args) {
|
export async function saveEvent(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function getPageviewMetrics(...args) {
|
export async function getPageviewMetrics(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ import { MYSQL, POSTGRESQL, CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
|||||||
|
|
||||||
export async function getPageviewParams(...args) {
|
export async function getPageviewParams(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ import {
|
|||||||
|
|
||||||
export async function getPageviewStats(...args) {
|
export async function getPageviewStats(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function getPageviews(...args) {
|
export async function getPageviews(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function savePageView(...args) {
|
export async function savePageView(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ import { getSessionByUuid } from 'queries';
|
|||||||
|
|
||||||
export async function createSession(...args) {
|
export async function createSession(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
import { CLICKHOUSE, RELATIONAL } from 'lib/constants';
|
||||||
import { rawQueryClickhouse, prisma, runAnalyticsQuery, runQuery } from 'lib/db';
|
import { rawQueryClickhouse, findUnique, prisma, runAnalyticsQuery, runQuery } from 'lib/db';
|
||||||
|
|
||||||
export async function getSessionByUuid(...args) {
|
export async function getSessionByUuid(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,5 +38,5 @@ async function clickhouseQuery(session_uuid) {
|
|||||||
where session_uuid = $1
|
where session_uuid = $1
|
||||||
`,
|
`,
|
||||||
params,
|
params,
|
||||||
);
|
).then(data => findUnique(data));
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function getSessionMetrics(...args) {
|
export async function getSessionMetrics(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ import {
|
|||||||
|
|
||||||
export async function getSessions(...args) {
|
export async function getSessions(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import { getDateFormatClickhouse, rawQuery, rawQueryClickhouse, runAnalyticsQuer
|
|||||||
|
|
||||||
export async function getActiveVisitors(...args) {
|
export async function getActiveVisitors(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ import {
|
|||||||
|
|
||||||
export async function getWebsiteStats(...args) {
|
export async function getWebsiteStats(...args) {
|
||||||
return runAnalyticsQuery({
|
return runAnalyticsQuery({
|
||||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
[RELATIONAL]: () => relationalQuery(...args),
|
||||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
[CLICKHOUSE]: () => clickhouseQuery(...args),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user