Hello all, I would like to build a crud builder, b...
# orm-help
l
Hello all, I would like to build a crud builder, but I don't know how to type a model.
Copy code
interface CrudServices<T> {
  getDocument: (id: number) => Promise<T>;
}

function buildCrudServices<T>(model): CrudServices<T> {
  const getDocument = (id: number): Promise<T> =>
    model.findUnique({ where: { id } });

  return { getDocument };
}
How do I type model? Each of my model have costum type in the prisma client.
n
Hey 👋 Could you please elaborate? Do you wish to get types which are generated by Prisma from your models?
l
@Nurul Hello Nurul!
Do you wish to get types which are generated by Prisma from your models?
yes and no. I have several model, for instance
prisma.users
et
prisma.teams
, and I want to create a common function that build crud operation from those model. So I want a type which is valid for
prisma.users
and
prisma.team
. For Mongoose it could be done with the
Model<T>
interface (see https://github.com/Automattic/mongoose/blob/master/types/index.d.ts#L261). I don't find a similar type for prisma.