HOME/posts/nextjs14-crud-server-action

Nextjs 14 CRUD with best practices -server action

Published On

Folder Structue

  • prisma
    • - schema.prisma
    • public
      • src

        Introduction

        In this lesson, I will create a full crud operation using nextjs 14. For this lesson I'm using prisma as a database ORM(Object-relational Mapping).

        Prisma Schema

        prisma/schema.prisma

        generator client {
          provider = "prisma-client-js"
        }
         
        datasource db {
          provider = "mongodb"
          url      = env("DATABASE_URL")
        }
         
        model User {
          id        String   @id @default(auto()) @map("_id") @db.ObjectId
          name      String
          role      String
          username  String   @unique
          createdAt DateTime @default(now())
          updatedAt DateTime @updatedAt
        }

        Happy coding!