最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How can I export my model's properties types from Prisma Schema? - Stack Overflow

matteradmin8PV0评论

Lets say I have this Prisma Schema :

model User {
  id             String   @id @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  email          String   @unique
  username       String   
}

Is there a way I can get lets say email's type in my app ?

  • One options I can e with is a file that will export types but that way everytime I make a change to my prisma schema I will have to go there and manually edit the type.

Lets say I have this Prisma Schema :

model User {
  id             String   @id @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  email          String   @unique
  username       String   
}

Is there a way I can get lets say email's type in my app ?

  • One options I can e with is a file that will export types but that way everytime I make a change to my prisma schema I will have to go there and manually edit the type.
Share Improve this question asked Aug 19, 2022 at 14:01 ValeriValeri 831 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Prisma by default generates types for all your models. You could import it like this:

import { PrismaClient, User } from '@prisma/client';

Your models will always be in sync with your schema file, anytime you change the schema file, you could execute npx prisma generate to update the PrismaClient and the generated types for your models.

Post a comment

comment list (0)

  1. No comments so far