Prisma Client: Basic CRUD
Once your schema is migrated, Prisma Client gives you a typed method for every model.
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
// Create
const user = await prisma.user.create({
data: { email: 'ada@example.com', name: 'Ada' },
});
// Read
const users = await prisma.user.findMany();
const one = await prisma.user.findUnique({ where: { id: 1 } });
// Update
const updated = await prisma.user.update({
where: { id: 1 },
data: { name: 'Ada Lovelace' },
});
// Delete
await prisma.user.delete({ where: { id: 1 } });
This needs a running Node.js process connected to a real PostgreSQL database, so it's read-only here, you'll run code exactly like this in the final project.
Notice the shape: every method takes a single options object (where, data, ...), and every method returns a fully-typed result, your editor knows user.email is a string without you writing a type annotation anywhere.