Prisma query multiple tables

So, I have 3 tables that need to be queried. Their schema are very much alike, underlined fields are basically shared between them. I need to 'join' them, I guess, and do a pagination based on timestamp. How would I go about doing this?
5 Replies
Diogo
Diogo13mo ago
const user = await prisma.user.findFirst({
include: {
widthdraws: true,
},
})
const user = await prisma.user.findFirst({
include: {
widthdraws: true,
},
})
something like this
Diogo
Diogo13mo ago
Prisma
Relation queries (Concepts)
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
.traevelliath
.traevelliath13mo ago
yeah, it's almost what I was looking for. Unfortunately, I wasn't able to come up with a query that would let me implement pagination, so I wound up using prisma.$queryRaw and writing some SQL. Thanks anyway.
Brendonovich
Brendonovich13mo ago
Can you provide some more details? I'm pretty sure what you're asking for can be done
.traevelliath
.traevelliath13mo ago
Okay, so: I have 3 tables with exact same schemas as per screenshot: Withdraw, Topup, Profit. I need to query them all 3 together, where userId matches with userId from current session and get rows ordered by 'createdAt'. Like this:
return await ctx.prisma.profit.findMany({
take : 5,
where : {
userId: id
},
orderBy: {
createdAt: 'desc'
}
});
return await ctx.prisma.profit.findMany({
take : 5,
where : {
userId: id
},
orderBy: {
createdAt: 'desc'
}
});