Writing raw queries

Hi, is there a way to write a raw query? It seems like context.$queryRaw is not a function
7 Replies
matijash
matijashβ€’14mo ago
hmm we don't expose it through context right now, but trying to think if there is some workaround you could use right now. What do you need it for exactly?
Zeko369
Zeko369β€’14mo ago
No description
matijash
matijashβ€’14mo ago
nice @Zeko369 ! This should def solve the issue but just to note it isn't the part of the official API yet. It would still be great to learn about your specific use case @GreatValorKing πŸ™‚
GreatValorKing
GreatValorKingβ€’14mo ago
This is the first time using Prisma, I needed to join 3 tables. Prisma docs and ChatGPT weren't helpful. In the end, I actually came up with the came code as @Zeko369, but I thought that there's gonna be something more official. Anyways thanks for help, that was quite quick πŸ™‚
Zeko369
Zeko369β€’14mo ago
Hmm, what do you mean join 3 tables? You can with include I.e.
entities.User.findUnique({
where: {id: 123},
includes: {
posts: {
includes: {
comments: true
}
}
}
})
entities.User.findUnique({
where: {id: 123},
includes: {
posts: {
includes: {
comments: true
}
}
}
})
shayne
shayneβ€’14mo ago
thanks for the help on this @Zeko369 that is an "unofficial" way to do it but should be stable for now. and yes, using Prisma for relationship includes would be ideal if you can @GreatValorKing πŸ‘
Filip
Filipβ€’14mo ago
And Prisma's API should generally be enough for most CRUD apps. Resorting to raw queries should rarely be necessary.