Object-Relational Mapping
An object-relational mapper (ORM) is a library that translates between the objects of a programming language and the tables of a relational database. Instead of writing SQL strings and manually converting result rows, a developer defines models in code and calls methods that the ORM compiles into queries, mapping the results back into typed objects. That removes repetitive boilerplate, reduces SQL injection risk through parameterized queries, and usually includes schema migrations so the database structure evolves alongside the codebase. Prisma is common in the TypeScript ecosystem and generates types from a schema file, Drizzle offers a lighter API that stays close to SQL, and SQLAlchemy, Django ORM, and ActiveRecord fill the same role in Python and Ruby. Most support connection pooling, relations, and transactions. The classic pitfall is the N+1 query problem, where loading a list and then reading a relation on each item silently issues one query per row; ORMs provide eager loading to avoid it, but only if the developer notices. Complex analytical queries using window functions or heavy aggregation are also often clearer and faster written as raw SQL, so teams mix both rather than treating the ORM as a complete replacement.