What Is ORM?
Object-Relational Mapping
An ORM (Object-Relational Mapping) maps database tables to programming language objects, letting you query and manipulate data using your language instead of raw SQL. Popular ORMs include Prisma (TypeScript), SQLAlchemy (Python), Hibernate (Java), and ActiveRecord (Ruby).
How ORM Works
Instead of writing SQL: SELECT * FROM users WHERE age > 21, an ORM lets you write: User.findMany({ where: { age: { gt: 21 } } }). The ORM generates the SQL, handles connections, and returns typed objects. Prisma generates TypeScript types from your schema for full type safety.
Key Concepts
- Schema Definition — Define database structure in code — models, fields, relationships — and sync to the database
- Query Builder — Programmatic API for building queries with type safety and autocompletion
- Migrations — Version-controlled database schema changes — add columns, create tables, modify constraints
Frequently Asked Questions
Should I use an ORM or raw SQL?
ORMs for CRUD operations and rapid development. Raw SQL for complex queries, performance-critical paths, and analytics. Many developers use both — ORM for 90% of queries, raw SQL for the rest.
Which ORM for TypeScript?
Prisma for the best developer experience and type safety. Drizzle ORM for a lighter, SQL-closer approach. Both are excellent.