server side events and ui improvemnt
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { omit } from 'ramda';
|
||||
|
||||
import { toDots } from '@mixan/common';
|
||||
import { redisPub } from '@mixan/redis';
|
||||
|
||||
import { ch, chQuery, formatClickhouseDate } from '../clickhouse-client';
|
||||
|
||||
@@ -12,7 +13,7 @@ export interface IClickhouseEvent {
|
||||
referrer: string;
|
||||
referrer_name: string;
|
||||
duration: number;
|
||||
properties: Record<string, string>;
|
||||
properties: Record<string, string | number | boolean>;
|
||||
created_at: string;
|
||||
country: string;
|
||||
city: string;
|
||||
@@ -91,30 +92,38 @@ export async function createEvent(payload: IServiceCreateEventPayload) {
|
||||
delete payload.properties.hash;
|
||||
}
|
||||
|
||||
return ch.insert({
|
||||
const event: IClickhouseEvent = {
|
||||
name: payload.name,
|
||||
profile_id: payload.profileId,
|
||||
project_id: payload.projectId,
|
||||
properties: toDots(omit(['_path'], payload.properties)),
|
||||
path: payload.path ?? '',
|
||||
created_at: formatClickhouseDate(payload.createdAt),
|
||||
country: payload.country ?? '',
|
||||
city: payload.city ?? '',
|
||||
region: payload.region ?? '',
|
||||
os: payload.os ?? '',
|
||||
os_version: payload.osVersion ?? '',
|
||||
browser: payload.browser ?? '',
|
||||
browser_version: payload.browserVersion ?? '',
|
||||
device: payload.device ?? '',
|
||||
brand: payload.brand ?? '',
|
||||
model: payload.model ?? '',
|
||||
duration: payload.duration,
|
||||
referrer: payload.referrer ?? '',
|
||||
referrer_name: payload.referrerName ?? '',
|
||||
};
|
||||
|
||||
const res = await ch.insert({
|
||||
table: 'events',
|
||||
values: [
|
||||
{
|
||||
name: payload.name,
|
||||
profile_id: payload.profileId,
|
||||
project_id: payload.projectId,
|
||||
properties: toDots(omit(['_path'], payload.properties)),
|
||||
path: payload.path ?? '',
|
||||
created_at: formatClickhouseDate(payload.createdAt),
|
||||
country: payload.country ?? '',
|
||||
city: payload.city ?? '',
|
||||
region: payload.region ?? '',
|
||||
os: payload.os ?? '',
|
||||
os_version: payload.osVersion ?? '',
|
||||
browser: payload.browser ?? '',
|
||||
browser_version: payload.browserVersion ?? '',
|
||||
device: payload.device ?? '',
|
||||
brand: payload.brand ?? '',
|
||||
model: payload.model ?? '',
|
||||
duration: payload.duration,
|
||||
referrer: payload.referrer ?? '',
|
||||
},
|
||||
],
|
||||
values: [event],
|
||||
format: 'JSONEachRow',
|
||||
});
|
||||
|
||||
redisPub.publish('event', JSON.stringify(transformEvent(event)));
|
||||
|
||||
return {
|
||||
...res,
|
||||
document: event,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export function createSqlBuilder() {
|
||||
offset: number | undefined;
|
||||
} = {
|
||||
where: {},
|
||||
from: 'events',
|
||||
from: 'openpanel.events',
|
||||
select: {},
|
||||
groupBy: {},
|
||||
orderBy: {},
|
||||
@@ -40,8 +40,8 @@ export function createSqlBuilder() {
|
||||
getSelect,
|
||||
getGroupBy,
|
||||
getOrderBy,
|
||||
getSql: () =>
|
||||
[
|
||||
getSql: () => {
|
||||
const sql = [
|
||||
getSelect(),
|
||||
getFrom(),
|
||||
getWhere(),
|
||||
@@ -51,6 +51,12 @@ export function createSqlBuilder() {
|
||||
getOffset(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' '),
|
||||
.join(' ');
|
||||
console.log('---');
|
||||
console.log(sql);
|
||||
console.log('---');
|
||||
|
||||
return sql;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user