Support Clickhouse insert without Kafka.

This commit is contained in:
Mike Cao 2024-07-04 20:30:15 -07:00
parent d501410a63
commit 9bf34bd5e4
3 changed files with 23 additions and 4 deletions

View file

@ -3,6 +3,7 @@ import { DATA_TYPE } from 'lib/constants';
import { uuid } from 'lib/crypto';
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
import { flattenJSON, getStringValue } from 'lib/data';
import clickhouse from 'lib/clickhouse';
import kafka from 'lib/kafka';
import prisma from 'lib/prisma';
import { DynamicData } from 'lib/types';
@ -59,6 +60,7 @@ async function clickhouseQuery(data: {
}) {
const { websiteId, sessionId, eventId, urlPath, eventName, eventData, createdAt } = data;
const { insert } = clickhouse;
const { getDateFormat, sendMessages } = kafka;
const jsonKeys = flattenJSON(eventData);
@ -79,7 +81,11 @@ async function clickhouseQuery(data: {
};
});
await sendMessages(messages, 'event_data');
if (kafka.enabled) {
await sendMessages(messages, 'event_data');
} else {
await insert('event_data', messages);
}
return data;
}