DEV Community

The Practical Developer
The Practical Developer

Posted on Originally published at practicaldevblog.blogspot.com

Prisma Explained: Databases Without Writing Raw SQL

Introduction

Working with a database from code usually means one of two pains: writing raw SQL strings (powerful, but no autocomplete and easy to mistype) or learning a heavy ORM with its own query language. Prisma, released in 2019, offers a third way for TypeScript and Node developers: define your data model once in a readable schema file, and Prisma generates a type-safe client — so database queries get autocomplete, type checking, and errors at write time instead of runtime.

Schema first, then a generated client

The workflow has three parts. First, a schema file describes your tables:

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String
  posts Post[]
}
model Post {
  id       Int    @id @default(autoincrement())
  title    String
  authorId Int
  author   User   @relation(fields: [authorId], references: [id])
}
Enter fullscreen mode Exit fullscreen mode

Second, Prisma Migrate turns schema changes into versioned migration files, so the database evolves safely alongside the code. Third, the generated client lets you query with ordinary TypeScript that the compiler checks:

const user = await prisma.user.findUnique({
  where: { email: "ayesha@example.com" },
  include: { posts: true },
});
Enter fullscreen mode Exit fullscreen mode

A typo in a field name becomes a compile error, not a broken query in production — and the relation (posts) loads in the same call, without hand-writing a join (the SQL post's joins, done for you).

The honest trade

Prisma's trade is abstraction: for very complex queries, raw SQL (the SQL and MySQL posts) is still more expressive, and Prisma adds a build step and a learning curve of its own concepts. It also historically focused on relational databases (PostgreSQL, MySQL, SQLite — all covered), with MongoDB support added later. The rule of thumb: Prisma for TypeScript apps where type safety and developer speed matter most; raw SQL or a query builder when queries get exotic or the project isn't TypeScript.

Takeaway

Prisma turns a readable schema into a type-safe database client, with migrations built in — so database mistakes become compile errors instead of production bugs. It is the modern default for TypeScript apps talking to relational databases.

Originally published at https://practicaldevblog.blogspot.com/2026/10/prisma-explained-databases-without.html

Top comments (0)