diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/lib/db.ts | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/lib/db.ts')
| -rw-r--r-- | src/lib/db.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/db.ts b/src/lib/db.ts new file mode 100644 index 0000000..7b6e836 --- /dev/null +++ b/src/lib/db.ts @@ -0,0 +1,40 @@ +export const PRISMA = 'prisma'; +export const POSTGRESQL = 'postgresql'; +export const CLICKHOUSE = 'clickhouse'; +export const KAFKA = 'kafka'; +export const KAFKA_PRODUCER = 'kafka-producer'; + +// Fixes issue with converting bigint values +BigInt.prototype.toJSON = function () { + return Number(this); +}; + +export function getDatabaseType(url = process.env.DATABASE_URL) { + const type = url?.split(':')[0]; + + if (type === 'postgres') { + return POSTGRESQL; + } + + return type; +} + +export async function runQuery(queries: any) { + if (process.env.CLICKHOUSE_URL) { + if (queries[KAFKA]) { + return queries[KAFKA](); + } + + return queries[CLICKHOUSE](); + } + + const db = getDatabaseType(); + + if (db === POSTGRESQL) { + return queries[PRISMA](); + } +} + +export function notImplemented() { + throw new Error('Not implemented.'); +} |