Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma FindMany input type

Hi I am currently using prisma 2 to query a database by using the findMany Method, example of how I do this is here

const data = await prisma.user.findMany({
    take: 10000,

    select: {
      A: {
        select: {
          B: true,
          C: true,
          D: true,
        },
      },
    }
}

I would like to implement it where I can define the object that this findMany takes externally, like

const obj = {
    take: 10000,

    select: {
      A: {
        select: {
          B: true,
          C: true,
          D: true,
        },
      }
    }

const data = await prisma.user.findMany(obj)

However I am having an issue as to getting the type for obj, hovering over the findMany function, it tells me that the type it takes is of type UserFindManyArgs however I cant seem to find a way to import this. Any advice on how to do this will be greatly appriciated

like image 328
user15032172 Avatar asked Aug 25 '26 06:08

user15032172


1 Answers

You can find these types under the Prisma namespace. So this should work:

import { Prisma } from '@prisma/client'

type T = Prisma.UserFindManyArgs
like image 121
Ryan Avatar answered Aug 26 '26 22:08

Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!