ORM

abbreviation

An ORM is software that maps objects in program code to tables and relationships in a relational database. ORM stands for Object-Relational Mapping.

The ORM retrieves an order as an object without the developer having to write SQL for that operation.

An application and a relational Glossary · In briefdatabaseA database is a structured collection of data that software can store, retrieve and modify. A database management system controls access to that data.Read more represent data differently. Code might work with a Customer object and properties such as a name and email address. The database stores that information in tables, columns and rows. The ORM translates between these representations.

How does an ORM map data?

A developer defines an object's fields and relationships in a model. The ORM uses that model to perform database operations. An instruction to retrieve a customer becomes an Glossary · In briefSQLSQL is a language for querying and managing data in a relational database and defining that database's structure.Read more query. The ORM then turns the database result into an object the application can use.

Many ORMs also help insert, update and delete data. They often provide tools for relationships and database migrations. Well-known examples include Prisma, Hibernate, Entity Framework and Active Record in Ruby on Rails.

When should you use SQL directly?

An ORM reduces repetitive work and keeps the data layer familiar within the programming language. The abstraction also makes the actual database Glossary · In briefqueryA query is a targeted instruction to a system to retrieve, filter, combine or modify data.Read more less visible. This can be a drawback for complex reports or queries that need to run quickly.

Many ORMs still allow direct SQL in those situations. A query builder offers another middle ground: it helps construct SQL queries programmatically but does not always turn results into domain objects. The appropriate approach depends on the query, Glossary · In briefdata modelA data model describes which data a system records, how that data is related and which rules it must satisfy.Read more and amount of control the application needs.