extension-read-replicas
extension-read-replicas copied to clipboard
Is there a sample that logs queries to a replica database?
I want to do the same thing as the code below. What I want to do is log the query to be executed. Is it possible to log the query for a read-only database?
const prisma = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
})
prisma.$on('query', async (e) => {
console.log(`${e.query} ${e.params}`)
})
Below is the code we tried.
const prismaClient = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
})
prismaClient.$on('query', async (e) => {
console.log(`${e.query} ${e.params}`)
})
const prisma = prismaClient.$extends(
readReplicas({
url: Config.DATABASE_URL_REPLICA,
})
)
await prisma.$primary().$queryRaw・・・ // This will be written to the log.
await prisma.$replica().$queryRaw・・・ // This is not written to the log.