CRUD operations
Adding your model to prisma
Edit the prisma/schema.prisma file to define your data model. For example:
model Articles { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) author User? @relation(fields: [authorId], references: [id]) authorId Int? @@index([authorId], name: "authorId") }
Migrate the model into the postgresql database with Replace add-article-model with the name you want to call the migration.
npx prisma migrate dev --name add-article-model
Generate the prisma client so it can build the typescript types for the model.
npx prisma generate
Create the CRUD apis within the nestjs application
Create a new service for the model
nest g resource articles
Now connect Prisma operations with NestJS
Go to the files articles.service and start adding the prisma operations in.
findAll() { return this.prisma.articles.findMany(); }
Create a new page in the frontend and add in the CRUD operations
Create a new page in the frontend and add in the CRUD operations.