An object-relational mapper, or ORM, is a library that lets code read and write database rows as objects and generates the SQL automatically. Instead of writing queries by hand, a developer works with classes and methods, and the ORM translates them into database commands and turns the results back into objects.

ORMs save time, keep database code consistent and often help with schema changes and with safe handling of query parameters. They are a common part of web frameworks.

The convenience has trade-offs. An ORM can generate inefficient queries, for example running one extra query per row in a list, and the generated SQL may be hard to see. Moving between ORMs or between versions of the same one can involve breaking changes. Using an ORM does not by itself remove the risk of injection if raw SQL is mixed in carelessly.

To use one safely, log and review the queries it produces, learn how it loads related data, use its parameter binding for any raw SQL, and add indexes where the queries need them. Keep it updated, and read release notes before upgrading.