What are ORMs and why should you use them?

Maps those objects

Odysee YouTube

Check out the video for some more elaboration on the topics below.

If you liked it and want to know when I post more videos, be sure to subscribe

I'm about to do a few videos on a some Go ORM packages and thought it wouldn't hurt to do a dedicated segment on just talking about what ORMs are and why you should or shouldn't use them.

What does ORM stand for?

ORM stands for Object Relation Mapping. Typically this means communicating with a system using a language other than the native language is expects.

An example of this would be a SQL database. A SQL database is expecting, well, a SQL query to interact with it, but what if we wanted to interact with it with something like a Golang program?

What does an ORM do?

An ORM library gives us the mechanism by which to perform Object Relation Mapping. This means we end up with structs or classes that represent something like a table in our database

In golang, we would get something like this:

user := models.Users().ByID(1)

Which would generate the following SQL query:

SELECT * FROM Users WHERE id = 1;

Pros & Cons of ORMs



What kinds of ORM libraries exist?

From my experience, there are two primary types of ORM libaries

Code-First ORM

A code first ORM uses the code written or generated by the user to generate the database schema and applies the schema to the database.

Some examples of code first ORMs:

Schema-First ORM

A schema first ORM reads the already defined schema from the database and generates from it, all the code necessary to interact with the database.

Some examples of schema first ORMs:

When to choose which?

Code-First ORM

Schema First ORM

#databases #orm