Use Prisma for type-safe database operations in Node.js.
Modern ORM with excellent developer experience.
Setup
npm install prisma @prisma/client
npx prisma init
Schema
// prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
name String
email String @unique
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
author User @relation(fields: [authorId], references: [id])
authorId Int
}
Usage
const user = await prisma.user.findUnique({
where: { email: ‘alice@example.com’ },
include: { posts: true }
});
Conclusion
Prisma makes database access type-safe and enjoyable!