Object-Relational Mapping (ORM) frameworks bridge the gap between object-oriented programming and relational databases by abstracting SQL operations into type-safe, language-native code. ORMs handle schema management, query generation, and data mapping automatically, enabling developers to work with database records as objects while the framework manages connection pooling, transactions, and query optimization. The key mental model to remember: ORMs trade some performance and control for developer productivity and type safety, but understanding when to use eager loading vs lazy loading, how to prevent N+1 queries, and when to drop down to raw SQL separates effective ORM usage from performance disasters.
What This Cheat Sheet Covers
This topic spans 15 focused tables and 84 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Popular ORM Frameworks
| Framework | Example | Description |
|---|---|---|
const user = await prisma.user.findUnique( { where: { id: 1 } }) | • Type-safe ORM for TypeScript/Node.js with schema-first design, auto-generated client, and Prisma Studio for visual database management • supports PostgreSQL, MySQL, SQLite, MongoDB, SQL Server. | |
@Entity()class User { @PrimaryGeneratedColumn() id: number;} | • Decorator-based ORM for TypeScript/JavaScript supporting both Active Record and Data Mapper patterns • features query builder, migrations, and multiple database support. | |
const User = sequelize.define('User', { name: DataTypes.STRING}); | • Promise-based ORM for Node.js with model definitions, hooks, transactions, and migrations • supports PostgreSQL, MySQL, MariaDB, SQLite, MSSQL. | |
const users = await db.select() .from(usersTable) .where(eq(usersTable.id, 1)); | • Lightweight, type-safe SQL query builder for TypeScript that feels like writing SQL • prioritizes performance and minimal abstraction over traditional ORM features. |