ORM
An ORM (Object-Relational Mapper) is a library that translates between application objects and relational database rows. ORMs handle query construction, parameter binding, result hydration into objects, schema migrations, and relationship navigation, so applications can work with domain objects instead of raw SQL strings.
Common ORMs by language
- JavaScript / TypeScript: Prisma, Drizzle, TypeORM, Sequelize, MikroORM, Kysely (query builder, not strictly ORM)
- Python: SQLAlchemy, Django ORM, Tortoise ORM, SQLModel, Peewee
- Ruby: Active Record, Sequel
- Java: Hibernate, Spring Data JPA, jOOQ
- Go: GORM, sqlc (code-generated, not classic ORM), ent
- .NET: Entity Framework Core
- Rust: Diesel, SeaORM, SQLx (query builder), Loco
ORM vs query builder vs raw SQL
- ORM (Active Record / Data Mapper). Maps tables to classes; rich object navigation and lazy loading. Risk: hidden N+1 queries.
- Query builder. Composes SQL through code without object mapping; explicit but typed.
- Raw SQL. Maximum control; least magic; pairs well with code generation (sqlc, sqlx).
Common considerations
- N+1 query problem: lazy associations triggered in loops; mitigated with eager loading.
- Migrations: keep schema in version control; tools include Prisma Migrate, Alembic, Flyway, Liquibase.
- Connection pooling: every ORM relies on a pool (HikariCP, pg-pool, PgBouncer externally).
🔗