2022-08-28 06:38:35 +02:00
|
|
|
export const PRISMA = 'prisma';
|
|
|
|
export const POSTGRESQL = 'postgresql';
|
|
|
|
export const MYSQL = 'mysql';
|
|
|
|
export const CLICKHOUSE = 'clickhouse';
|
|
|
|
export const KAFKA = 'kafka';
|
|
|
|
export const KAFKA_PRODUCER = 'kafka-producer';
|
|
|
|
|
|
|
|
// Fixes issue with converting bigint values
|
2023-12-03 12:07:03 +01:00
|
|
|
BigInt.prototype['toJSON'] = function () {
|
2022-07-16 07:21:37 +02:00
|
|
|
return Number(this);
|
2022-07-07 14:55:43 +02:00
|
|
|
};
|
|
|
|
|
2022-08-27 07:43:31 +02:00
|
|
|
export function getDatabaseType(url = process.env.DATABASE_URL) {
|
2022-09-29 00:36:41 +02:00
|
|
|
const type = url && url.split(':')[0];
|
2022-07-16 01:47:38 +02:00
|
|
|
|
|
|
|
if (type === 'postgres') {
|
|
|
|
return POSTGRESQL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2023-12-03 12:07:03 +01:00
|
|
|
export async function runQuery(queries: any) {
|
2024-02-04 08:19:29 +01:00
|
|
|
if (process.env.CLICKHOUSE_URL) {
|
2022-08-27 07:43:31 +02:00
|
|
|
if (queries[KAFKA]) {
|
2022-08-05 02:43:47 +02:00
|
|
|
return queries[KAFKA]();
|
|
|
|
}
|
2022-08-27 07:43:31 +02:00
|
|
|
|
2022-07-25 18:47:11 +02:00
|
|
|
return queries[CLICKHOUSE]();
|
2022-07-16 01:47:38 +02:00
|
|
|
}
|
2024-02-04 08:19:29 +01:00
|
|
|
|
|
|
|
const db = getDatabaseType();
|
|
|
|
|
|
|
|
if (db === POSTGRESQL || db === MYSQL) {
|
|
|
|
return queries[PRISMA]();
|
|
|
|
}
|
2022-07-16 01:47:38 +02:00
|
|
|
}
|
2023-07-25 08:06:16 +02:00
|
|
|
|
|
|
|
export function notImplemented() {
|
|
|
|
throw new Error('Not implemented.');
|
|
|
|
}
|