What Is an Orm, How Does It Work, and How Should I Use One? [Closed]
Someone Suggested I Use an Orm for a Project That I'm Designing, but I'm Having Trouble Finding Information on What It Is or How It Works. Can Anyone Give Me a...
Someone suggested I use an ORM for a project that I'm designing, but I'm having trouble finding information on what it is or how it works.
Can anyone give me a brief explanation of what an ORM is and how it works and how I should get started using one?
5 Answers
Must Read
Introduction
Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm. When talking about ORM, most people are referring to a library that implements the Object-Relational Mapping technique, hence the phrase "an ORM".
An ORM library is a completely ordinary library written in your language of choice that encapsulates the code needed to manipulate the data, so you don't use SQL anymore; you interact directly with an object in the same language you're using.
For example, here is a completely imaginary case with a pseudo language:
You have a book class, you want to retrieve all the books of which the author is "Linus". Manually, you would do something like that:
book_list = new List();
sql = "SELECT book FROM library WHERE author = 'Linus'";
data = query(sql); // I over simplify ...
while (row = data.next())
{
book = new Book();
book.setAuthor(row.get('author');
book_list.add(book);
}
With an ORM library, it would look like this:
book_list = BookTable.query(author="Linus");
The mechanical part is taken care of automatically via the ORM library.