mirror of
https://github.com/umami-software/umami.git
synced 2026-02-21 04:55:36 +01:00
feat: support mongodb connection
This commit is contained in:
parent
586529a5ca
commit
bb30b43a8e
9 changed files with 370 additions and 30 deletions
|
|
@ -4,6 +4,7 @@ export const MYSQL = 'mysql';
|
|||
export const CLICKHOUSE = 'clickhouse';
|
||||
export const KAFKA = 'kafka';
|
||||
export const KAFKA_PRODUCER = 'kafka-producer';
|
||||
export const MONGODB = 'mongodb';
|
||||
|
||||
// Fixes issue with converting bigint values
|
||||
BigInt.prototype.toJSON = function () {
|
||||
|
|
@ -15,6 +16,8 @@ export function getDatabaseType(url = process.env.DATABASE_URL) {
|
|||
|
||||
if (type === 'postgres') {
|
||||
return POSTGRESQL;
|
||||
} else if (type === 'mongodb+srv') {
|
||||
return MONGODB;
|
||||
}
|
||||
|
||||
return type;
|
||||
|
|
@ -23,7 +26,7 @@ export function getDatabaseType(url = process.env.DATABASE_URL) {
|
|||
export async function runQuery(queries) {
|
||||
const db = getDatabaseType(process.env.CLICKHOUSE_URL || process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL || db === MYSQL) {
|
||||
if (db === POSTGRESQL || db === MYSQL || db === MONGODB) {
|
||||
return queries[PRISMA]();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import prisma from '@umami/prisma-client';
|
||||
import moment from 'moment-timezone';
|
||||
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
|
||||
import { MYSQL, POSTGRESQL, getDatabaseType, MONGODB } from 'lib/db';
|
||||
import { getEventDataType } from './eventData';
|
||||
import { FILTER_COLUMNS } from './constants';
|
||||
|
||||
|
|
@ -51,6 +51,10 @@ function getDateQuery(field: string, unit: string, timezone?: string): string {
|
|||
|
||||
return `date_format(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
if (db === MONGODB) {
|
||||
return MYSQL_DATE_FORMATS[unit];
|
||||
}
|
||||
}
|
||||
|
||||
function getTimestampInterval(field: string): string {
|
||||
|
|
@ -152,6 +156,7 @@ async function rawQuery(query: string, params: never[] = []): Promise<any> {
|
|||
|
||||
export default {
|
||||
...prisma,
|
||||
getDatabaseType: () => getDatabaseType(process.env.DATABASE_URL),
|
||||
getDateQuery,
|
||||
getTimestampInterval,
|
||||
getFilterQuery,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue