Grégory D'Angelo
10/01/2022, 8:14 AMinclude
or select
?
I'm asking that because I'm wrapping my Prisma functions inside service functions for a Node.js project. Those functions accept include
or select
as arguments and I'd like to keep type-safety, but I'm not sure if it is actually possible or the best way to do it.
Any advice or suggestions from what you've seen?
Here's an example:
export interface FindQuizzesByStatusInput {
status: Status;
take: number;
after?: string | null;
include?: { [key: string]: any }; // not great for type-safety!!!
}
export const findQuizzesByStatus = async (
input: FindQuizzesByStatusInput
): Promise<Quiz[]> => {
// ...
}
Thanks!Jarupong
10/01/2022, 11:20 AMasync findManyForPagination(
input?: Prisma.AddressFindManyArgs
): Promise<PrismaTypes.Address[]> {
const { select, include, cursor, where, take, skip } = input || {}
return this.db.address.findMany({
where: {
...where,
shopId: this.context.shopId,
...createOrganisationFilter(this.context),
},
take,
skip,
...(cursor && { cursor }),
...(!select && include && { include }),
})
}
Jarupong
10/01/2022, 11:20 AMGrégory D'Angelo
10/02/2022, 9:06 AMGrégory D'Angelo
10/03/2022, 5:31 AMJarupong
10/03/2022, 5:32 AM