ORM (Object-Relational Mapping)
Object-Relational Mapping
A mechanism that lets you operate a database using the same style you write your program in.
In Simple Terms
ORM is a mechanism that maps a program's "classes" to a database's "tables," and the individual "objects" created from those classes to "rows" within those tables. For example, if you define a "User" class to handle user information, it gets linked to a "users" table in the database. Furthermore, an "object" holding a specific user's data is stored as a single "row" in the table. This lets you work directly with the program's data structures mapped onto the database's format.
Behind the Name
The name ORM comes from Object, Relational, and Mapping. Object refers to how data is handled in a program, Relational refers to the database's format, and Mapping means connecting the two. Together, they describe the role of linking two worlds—programs and databases—that structure data in fundamentally different ways.
Take a Closer Look!
ORM is a technology that automatically maps objects—the data structures used in programming languages—to the data stored in a database.
Programming languages and databases handle and structure data in fundamentally different ways. Because of this, databases used to require writing dedicated, complex commands one by one to operate them.
Put simply, ORM acts like an interpreter that sits between these two worlds and translates for them.
When an engineer writes code in the programming language they're comfortable with, ORM converts it into commands the database can understand. This makes code easier to read and reduces mistakes caused by typos or errors.
In practice, it's used to develop applications in various languages such as Python and Ruby.
Even when the type of database changes, ORM absorbs the difference, which means there's less need to rewrite large parts of the program itself.