ORM

Prisma ORM: The Modern Way to Talk to Your Database

P

Prasanna Joshi

Author

November 15, 2024
11 min read

Introduction to Prisma

Prisma is a next-generation ORM that consists of the following tools:

  • Prisma Client: Auto-generated, type-safe query builder for Node.js & TypeScript.
  • Prisma Migrate: Migration system.
  • Prisma Studio: GUI to view and edit data in your database.

The Schema File

Everything starts in schema.prisma:

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

Type-Safe Queries

Prisma generates a client based on your schema, giving you incredible autocomplete:

const user = await prisma.user.findUnique({
  where: { email: 'alice@prisma.io' },
  include: { posts: true }, // Typed result includes posts!
});

Tags

#Prisma#Database#TypeScript#SQL

Share this article

About the Author

P

Prasanna Joshi

Content Writer

Passionate about technology and sharing knowledge with the community.

Stay Updated

Get the latest articles delivered to your inbox