mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Display page views and unique visitors.
This commit is contained in:
parent
bdcdcd9d13
commit
ce92c7897d
16 changed files with 162 additions and 44 deletions
15
lib/db.js
15
lib/db.js
|
|
@ -1,4 +1,5 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const options = {
|
||||
log: [
|
||||
|
|
@ -9,13 +10,21 @@ const options = {
|
|||
],
|
||||
};
|
||||
|
||||
function logQuery(e) {
|
||||
if (process.env.LOG_QUERY) {
|
||||
console.log(chalk.yellow(e.params), '->', e.query, chalk.greenBright(`${e.duration}ms`));
|
||||
}
|
||||
}
|
||||
|
||||
let prisma;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient(options);
|
||||
prisma.on('query', logQuery);
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient(options);
|
||||
global.prisma.on('query', logQuery);
|
||||
}
|
||||
|
||||
prisma = global.prisma;
|
||||
|
|
@ -23,12 +32,6 @@ if (process.env.NODE_ENV === 'production') {
|
|||
|
||||
export default prisma;
|
||||
|
||||
prisma.on('query', e => {
|
||||
if (process.env.LOG_QUERY) {
|
||||
console.log(`${e.params} -> ${e.query} (${e.duration}ms)`);
|
||||
}
|
||||
});
|
||||
|
||||
export async function runQuery(query) {
|
||||
return query.catch(e => {
|
||||
console.error(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue