mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 04:25:39 +01:00
Implement Cockroachdb interaction
This commit is contained in:
parent
38c9da4e55
commit
33422d8a6c
3 changed files with 22 additions and 6 deletions
|
|
@ -2,7 +2,7 @@ import { PrismaClient } from '@prisma/client';
|
|||
import chalk from 'chalk';
|
||||
import moment from 'moment-timezone';
|
||||
import debug from 'debug';
|
||||
import { PRISMA, MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
|
||||
import { PRISMA, MYSQL, POSTGRESQL, COCKROACHDB, getDatabaseType } from 'lib/db';
|
||||
import { FILTER_IGNORED } from 'lib/constants';
|
||||
|
||||
const MYSQL_DATE_FORMATS = {
|
||||
|
|
@ -55,6 +55,13 @@ function getClient(options) {
|
|||
function getDateQuery(field, unit, timezone) {
|
||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||
|
||||
if (db == COCKROACHDB) {
|
||||
if (timezone) {
|
||||
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}')::TIMESTAMP)`;
|
||||
}
|
||||
return `to_char(date_trunc('${unit}', ${field})::TIMESTAMP)`;
|
||||
}
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (timezone) {
|
||||
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
|
|
@ -76,7 +83,7 @@ function getDateQuery(field, unit, timezone) {
|
|||
function getTimestampInterval(field) {
|
||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (db === POSTGRESQL || db === COCKROACHDB) {
|
||||
return `floor(extract(epoch from max(${field}) - min(${field})))`;
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +95,7 @@ function getTimestampInterval(field) {
|
|||
function getJsonField(column, property, isNumber) {
|
||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (db === POSTGRESQL || db === COCKROACHDB) {
|
||||
let accessor = `${column} ->> '${property}'`;
|
||||
|
||||
if (isNumber) {
|
||||
|
|
@ -229,7 +236,7 @@ function parseFilters(table, column, filters = {}, params = [], sessionKey = 'se
|
|||
async function rawQuery(query, params = []) {
|
||||
const db = getDatabaseType(process.env.DATABASE_URL);
|
||||
|
||||
if (db !== POSTGRESQL && db !== MYSQL) {
|
||||
if (db !== POSTGRESQL && db !== MYSQL && db !== COCKROACHDB) {
|
||||
return Promise.reject(new Error('Unknown database.'));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue