mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
clickhouse inserts
This commit is contained in:
parent
6ea2282f82
commit
65910c7348
13 changed files with 146 additions and 40 deletions
|
|
@ -1,8 +1,20 @@
|
|||
import { prisma, runQuery } from 'lib/db';
|
||||
import { CLICKHOUSE, RELATIONAL, URL_LENGTH } from 'lib/constants';
|
||||
import {
|
||||
getDateFormatClickhouse,
|
||||
prisma,
|
||||
rawQueryClickhouse,
|
||||
runAnalyticsQuery,
|
||||
runQuery,
|
||||
} from 'lib/db';
|
||||
|
||||
import { URL_LENGTH } from 'lib/constants';
|
||||
export async function saveEvent(...args) {
|
||||
return runAnalyticsQuery({
|
||||
[`${RELATIONAL}`]: () => relationalQuery(...args),
|
||||
[`${CLICKHOUSE}`]: () => clickhouseQuery(...args),
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveEvent(website_id, session_id, url, event_type, event_value) {
|
||||
async function relationalQuery(website_id, { session_id, url, event_type, event_value }) {
|
||||
return runQuery(
|
||||
prisma.event.create({
|
||||
data: {
|
||||
|
|
@ -15,3 +27,20 @@ export async function saveEvent(website_id, session_id, url, event_type, event_v
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function clickhouseQuery(website_id, { session_uuid, url, event_type, event_value }) {
|
||||
const params = [
|
||||
website_id,
|
||||
session_uuid,
|
||||
url?.substr(0, URL_LENGTH),
|
||||
event_type?.substr(0, 50),
|
||||
event_value?.substr(0, 50),
|
||||
];
|
||||
|
||||
return rawQueryClickhouse(
|
||||
`
|
||||
insert into umami_dev.event (created_at, website_id, session_uuid, url, event_type, event_value)
|
||||
values (${getDateFormatClickhouse(new Date())}, $1, $2, $3, $4, $5);`,
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue