P
Prisma2mo ago
DennisK

Whenever you extend your PrismaClient with Pulse, you don't have access to $on anymore. Why?

Why is it possible to do this:
const client = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
{ level: 'warn', emit: 'stdout' },
],
})
client.$on('query', async (e) => {
if (e.duration < logThreshold) return
const color =
e.duration < logThreshold * 1.1
? 'green'
: e.duration < logThreshold * 1.2
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
const dur = chalk[color](`${e.duration}ms`)
console.info(`prisma:query - ${dur} - ${e.query}`)
})

void client.$connect()
const client = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
{ level: 'warn', emit: 'stdout' },
],
})
client.$on('query', async (e) => {
if (e.duration < logThreshold) return
const color =
e.duration < logThreshold * 1.1
? 'green'
: e.duration < logThreshold * 1.2
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
const dur = chalk[color](`${e.duration}ms`)
console.info(`prisma:query - ${dur} - ${e.query}`)
})

void client.$connect()
And not this:
const client = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
{ level: 'warn', emit: 'stdout' },
],
}).$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
}),
).$on('query', async (e) => {
if (e.duration < logThreshold) return
const color =
e.duration < logThreshold * 1.1
? 'green'
: e.duration < logThreshold * 1.2
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
const dur = chalk[color](`${e.duration}ms`)
console.info(`prisma:query - ${dur} - ${e.query}`)
})
const client = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
{ level: 'warn', emit: 'stdout' },
],
}).$extends(
withPulse({
apiKey: process.env.PULSE_API_KEY,
}),
).$on('query', async (e) => {
if (e.duration < logThreshold) return
const color =
e.duration < logThreshold * 1.1
? 'green'
: e.duration < logThreshold * 1.2
? 'blue'
: e.duration < logThreshold * 1.3
? 'yellow'
: e.duration < logThreshold * 1.4
? 'redBright'
: 'red'
const dur = chalk[color](`${e.duration}ms`)
console.info(`prisma:query - ${dur} - ${e.query}`)
})
No description
1 Reply
DennisK
DennisK2mo ago
Ha, and also the type of the Transaction Client has changed for some reason now
tx: Prisma.TransactionClient,
tx: Prisma.TransactionClient,
No description
Want results from more Discord servers?
Add your server