mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-25 02:36:20 +01:00
fix relational
This commit is contained in:
parent
1ba7b76072
commit
b29cece7ef
@ -13,7 +13,10 @@ export function getDatabase(database, databaseType, fallback) {
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
return getDatabase(fallback);
|
||||
if (fallback) {
|
||||
return getDatabase(fallback);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return type;
|
||||
|
@ -34,11 +34,15 @@ const kafka = global.kafka || getClient();
|
||||
let kafkaProducer = null;
|
||||
|
||||
(async () => {
|
||||
kafkaProducer = global.kakfaProducer || (await getProducer());
|
||||
if (kafka) {
|
||||
kafkaProducer = global.kakfaProducer || (await getProducer());
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
global.kafka = kafka;
|
||||
global.kakfaProducer = kafkaProducer;
|
||||
if (kafka) {
|
||||
global.kakfaProducer = kafkaProducer;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
POSTGRESQL,
|
||||
POSTGRESQL_DATE_FORMATS,
|
||||
} from 'lib/constants';
|
||||
import { getDatabase } from './db';
|
||||
import { getDatabase } from 'lib/db';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
const options = {
|
||||
@ -32,6 +32,7 @@ function getClient(options) {
|
||||
|
||||
return prisma;
|
||||
}
|
||||
|
||||
const prisma = global.prisma || getClient(options);
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
@ -41,7 +42,7 @@ if (process.env.NODE_ENV !== 'production') {
|
||||
export { prisma };
|
||||
|
||||
export function getDateQuery(field, unit, timezone) {
|
||||
const db = getDatabase();
|
||||
const db = getDatabase(process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (timezone) {
|
||||
@ -61,6 +62,18 @@ export function getDateQuery(field, unit, timezone) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getTimestampInterval(field) {
|
||||
const db = getDatabase(process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `floor(extract(epoch from max(${field}) - min(${field})))`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `floor(unix_timestamp(max(${field})) - unix_timestamp(min(${field})))`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getFilterQuery(table, column, filters = {}, params = []) {
|
||||
const query = Object.keys(filters).reduce((arr, key) => {
|
||||
const filter = filters[key];
|
||||
@ -151,7 +164,7 @@ export async function runQuery(query) {
|
||||
}
|
||||
|
||||
export async function rawQuery(query, params = []) {
|
||||
const db = getDatabase(process.env.DATABASE_URL, process.env.DATABASE_TYPE);
|
||||
const db = getDatabase(process.env.DATABASE_URL);
|
||||
|
||||
if (db !== POSTGRESQL && db !== MYSQL) {
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
|
Loading…
Reference in New Issue
Block a user