What you'll build
An application that connects to a real PostgreSQL database, where you can create, read, update, and delete records. You'll use Prisma as an ORM to define your models with TypeScript, generate automatic migrations, and have perfect autocompletion in your editor. When finished, you'll have a functional API with REST endpoints and an interface with data tables and forms that you can adapt to any entity in your project.
Setup
pnpm add prisma @prisma/client
npx prisma init
Step 1: Ask an AI for the CRUD
I need a complete CRUD in Next.js with:
- PostgreSQL + Prisma
- Model: User (id, email, name, createdAt)
- API routes for CRUD
- Page with users table
- Form to create/edit
- Validation with Zod
- TypeScript
Give me the Prisma schema and complete code.
Prisma Schema
// prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
createdAt DateTime @default(now())
}
npx prisma migrate dev --name init
npx prisma generate
API Route
// app/api/users/route.ts
import { prisma } from '@/lib/prisma'
export async function GET() {
const users = await prisma.user.findMany()
return Response.json(users)
}
export async function POST(request: Request) {
const body = await request.json()
const user = await prisma.user.create({ data: body })
return Response.json(user)
}
Next step
โ Real-time Chat