W
Wasp7d ago
dexie

Prisma logging (and other PrismaClient modifications)

Hello! When using prisma I am used to debugging queries by logging them using the following:
prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
prisma.$on('query', (e) => {
console.log('Query: ' + e.query)
console.log('Params: ' + e.params)
console.log('Duration: ' + e.duration + 'ms')
})
Is it possible to achieve something like this when using Wasp? Additionally, there is "client extensions" feature in Prisma, which would be amazing to use in Wasp: i.e.
const extendedPrisma = prisma
.$extends({
result: {
user: {
fullName: {
needs: { name: true, surename: true },
compute(data) {
return data.name + " " + data.surname
},
},
},
},
})
const extendedPrisma = prisma
.$extends({
result: {
user: {
fullName: {
needs: { name: true, surename: true },
compute(data) {
return data.name + " " + data.surname
},
},
},
},
})
10 Replies
kapa.ai
kapa.ai7d ago
Hi @dexie. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, I can partially answer your question about Prisma logging and client modifications in Wasp. However, there are some limitations to what I can confidently say based on the available information. Regarding Prisma logging: The knowledge sources don't provide specific information about enabling Prisma query logging in Wasp as you've described. However, Wasp does use Prisma for database interactions, so it's possible that similar functionality could be implemented. Regarding Prisma client extensions: Wasp is aware of the "client extensions" feature in Prisma, which has replaced the older middleware approach. According to the Github issue about migrating to the latest Prisma (https://github.com/wasp-lang/wasp/issues/1281), Wasp developers are considering implementing this feature: "Prisma now has "client extensions" feature, that enables hooking into various parts of Prisma Client. It replaces Prisma client middleware, which therefore becomes deprecated. If I am correct, we use Prisma middleware at the moment, specifically for hashing the user password, possibly some other things. We should look into using the "client extensions" for this now." However, as of the knowledge provided, it doesn't appear that Wasp has fully implemented support for Prisma client extensions yet. For the most up-to-date information on Prisma support in Wasp, you might want to check the official Wasp documentation on Prisma configuration (https://wasp-lang.dev/docs/data-model/backends#prisma-configuration). This page discusses some Prisma-related features, but it doesn't mention the specific logging or client extensions you're asking about. If you need these specific Prisma features, you might want to reach out to the Wasp community or developers directly to inquire about current support or potential workarounds. The Wasp team is actively working on expanding Prisma support, as evidenced by the Github issue about expanding Prisma support (https://github.com/wasp-lang/wasp/issues/641), so these features might be implemented in the future. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @dexie, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Filip
Filip6d ago
Hey @dexie! Yes, you can do anything you want with Prisma. Check this out: https://wasp-lang.dev/docs/data-model/entities#using-entities-directly And I think a good place to initialize the debugging is the server setup function: https://wasp-lang.dev/docs/project/server-config#setup-function As for the extension... Did you try using it? Wasp might support it out of the box P.S. 1 out of every 100 users asking questions here takes their time to write a concise and well-formatted question. Thanks for being that one user ❤️
dexie
dexieOP6d ago
Oh, didn't think about server setup fn! Will try extending prisma now. I am hesitant regarding typesafety of extensions doing it this way, because you are supposed to used ExtendedPrismaClient type instead of bare PrismaClient, but will report back soon
Filip
Filip6d ago
Oh, I think I understand the issue You'd be extending the client in the server setup function but then wouldn't have a way to use it in your operations Yes, that might be tricky Let me think about it for a minute, see what we can do
dexie
dexieOP6d ago
Oh no, no luck with logging, too. Log events are supposed to be enabled when instantiating PrismaClient, i.e.
const prisma = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
})
const prisma = new PrismaClient({
log: ['query', 'info', 'warn', 'error'],
})
MEE6
MEE66d ago
Wohooo @dexie, you just became a Waspeteer level 1!
Filip
Filip6d ago
Ah crap, yeah, we don't support extending the Prisma client just yet But you could monkey patch it It's not elegant at all, but if you go into node_modules/wasp/server/dbClient.ts and edit the code there, you'll get what you want Unfortunately, Wasp overrites this file on every build so you'd have to somehow ensure to patch it each time I'll create an issue for customizing Prisma right away Sorry for the pain, this is very inconvenient
dexie
dexieOP6d ago
yeah, got it, thank you!
Filip
Filip6d ago
Ok, I created an issue and linked this thread: https://github.com/wasp-lang/wasp/issues/2433 Thanks again @dexie
miho
miho5d ago
GitHub
Prisma setup hook · Issue #2116 · wasp-lang/wasp
Prisma supports client extensions: https://www.prisma.io/docs/orm/prisma-client/client-extensions which for: You can use Prisma Client extensions to add functionality to your models, result objects...

Did you find this page helpful?