How Prisma ORM Saved Me from SQL Headaches

How Prisma ORM Saved Me from SQL Headaches

Every project I touched had the same villain: database queries. Endless SELECT*, tricky JOINs, and debugging queries at 2 AM.😖

Sure, SQL is powerful — but it’s also low-level. Writing queries again and again for simple operations felt like reinventing the wheel. At some point, I asked myself: “Yaar, why can’t I just talk to my database like I talk to my code objects?”

That’s when I stumbled upon ORMs.


The ORM Discovery Moment

One day, while ranting to a senior in an internship, he casually said: “Bhai, don't worry, here we use an ORM?”

I was like: “ORM? 🧐?”

Upon investigating, I realized — ORM (Object Relational Mapper) is literally a translator between my code and the database. Instead of me writing raw SQL, ORM lets me write in my programming language, and it converts that to SQL (or NoSQL) behind the scenes.

Code (JS/TS)  --->  Prisma ORM  --->  Database (SQL / NoSQL)        

Suddenly… it felt like magic.


First Encounter with Prisma

Since I was in the JS/TS ecosystem, I landed on Prisma ORM. Clean docs, type safety, and the promise of “talk to your database like it’s just another object in your code”.

I gave it a try. And man… this was a game changer.


The Setup

👉 Step 1: Install

npm install prisma --save-dev
npm install @prisma/client        

👉 Step 2: Init

npx prisma init        

Boom! A prisma/schema.prisma file appears. This file is like your DB blueprint. Instead of CREATE TABLE SQLs, you just define models here.

👉 Step 3: Define a Model in schema.prisma

model User {
  id    Int     @id @default(autoincrement())
  name  String
  email String  @unique
}        

This literally defines a table without writing SQL 🤯🤯

👉 Step 4: Migration

npx prisma migrate dev --name init        

“OK? What’s happening here?” Turns out, Prisma actually:

  • Creates a folder with migration files (like Git commits for schema).
  • Runs SQL under the hood (like CREATE TABLE User (...)).
  • Keeps track of every schema change.

Article content

So tomorrow if your teammate asks “what changed in DB last week?”, you can just point to the migration history. No more “umm… I forgot.”

👉 Step 5: Generate Client

npx prisma generate        

This part blew me away🤯🤯. Behind the scenes, Prisma creates a fully typed client. Now my IDE started suggesting queries like findMany, create, update.

If we type prisma.users, TypeScript instantly yells — “bro, it’s user, not users.” Like… a database that corrects before we even run the code? Chef’s kiss. 👌🤌


Writing Queries Felt Different

// Create
await prisma.user.create({
  data: { name: "Yash", email: "yash@example.com" }
})

// Read
const users = await prisma.user.findMany()

// Update
await prisma.user.update({
  where: { id: 1 },
  data: { name: "Updated Yash" }
})        

Compare this to raw SQL — it’s just so much cleaner. And since everything is type-safe, no more runtime surprises.


The Mind-Boggling Moment 🌀

I was already impressed with migrations and type safety but there was yet to come the main advantage of an ORM:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}        

If I switch postgresql → mongodb … BAM 💥 Prisma works with MongoDB too (a NoSQL database)!

That one word swap felt like a superpower. I realized I could go from SQL to NoSQL without rewriting my entire data layer. For me, that was the moment Prisma went from “cool tool” → absolute beast.


Wrapping It Up (but Not Like Docs 😉)

Looking back, raw SQL gave me sleepless nights. Prisma turned that nightmare into something I actually enjoy.

Instead of thinking: “Ugh, another query to write”, I now think: “Nice, let’s just call a function and let Prisma handle the rest.”

Honestly, if raw SQL is like driving a bullock cart through the jungle, Prisma ORM is the express highway — smooth, fast, and modern 🚀


✨ Have you tried Prisma ORM yet?Would love to know what your “aha moment” was with ORMs in general. Drop it in the comments 👇


#Prisma #ORM #JavaScript #TypeScript #WebDev #NodeJS #SQL #MongoDB #BackendDevelopment #DeveloperJourney

To view or add a comment, sign in

More articles by Yash Patil

Others also viewed

Explore content categories