• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
project logo

nmsilva

my-portfolio

Starter template for a markdown blog
Public
Like
my-portfolio
Home
Code
5
docs
4
posts
5
Layout.tsx
README.md
H
index.tsx
Environment variables
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
posts
/
orm-vs-raw-sql.md
Code
/
posts
/
orm-vs-raw-sql.md
Search
…
Viewing readonly version of main branch: v23
View latest version
orm-vs-raw-sql.md
slug:
orm-vs-raw-sql
date:
Mar 10, 2026
readTime_en:
6 min read
readTime_pt:
6 min leitura
title_en:
Why I stopped using ORM and went back to raw SQL
title_pt:
Por que deixei de usar ORM e voltei ao SQL direto
excerpt_en:
After years of Sequelize and Prisma, I hit a wall with complex queries. Here's what I learned switching back to pg and writing SQL by hand.
excerpt_pt:
Depois de anos com Sequelize e Prisma, cheguei a um limite com queries complexas. O que aprendi ao voltar ao pg e escrever SQL Γ  mΓ£o.
tags:
Node.js, PostgreSQL, Backend

The problem with ORMs at scale

I've used Sequelize, TypeORM, and Prisma across different projects. For simple CRUD apps they're great β€” you get type safety, migrations, and a nice API out of the box. But once your queries grow beyond a few joins, things start to fall apart.

The turning point for me was a reporting query at Dragonboat. It involved multiple CTEs, window functions, and conditional aggregations. The Prisma version was a wall of `$queryRaw` with TypeScript fighting me every step. The raw SQL version was clean, readable, and 3x faster.

What I switched to

I moved to postgres (the `sql` package by porsager). It gives you tagged template literals with automatic parameterisation, so SQL injection is still handled correctly:

```ts const users = await sql` SELECT id, name, email FROM users WHERE active = true AND created_at > ${since} ORDER BY created_at DESC LIMIT ${limit} `; ```

No magic. No hidden N+1 queries. No wondering what SQL your ORM is actually generating.

Migrations

The one thing ORMs genuinely do well is migrations. I replaced that with db-migrate for structured migrations and a simple `schema.sql` file as source of truth. Not glamorous, but it works.

When I'd still use an ORM

  • Greenfield CRUD-heavy apps where speed of development matters more than performance
  • Teams where not everyone is comfortable with SQL
  • Simple one-table queries where the ORM adds zero friction

For anything else? Write the SQL. You'll thank yourself later.

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2026 Val Town, Inc.