NodeJS & PostgreSQL: ORM Overview
In the last two parts, we learned how to connect a database to a server:
What does an ORM do?
In short, an ORM is a layer between the server and the database.
The server talks with the ORM and the ORM talks to the database.
The ORM creates objects, that map to the relational data.
It handles your queries, so you don’t have to write native SQL, you can query the database with your application language.
List of ORMs:
- sequelize: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server
- TypeORM: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Oracle, sql.js, CockroachDB
- objection: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Oracle, Amazon Redshift
Comparison on npmtrends
If you use
MongoDB, you can use an ODM, e.g.
- you don’t have to learn/know/write SQL, because the ORM handles it
- it will be easier to change your database dialect
- your application is less vulnerable to SQL injections
- you have to learn the ORM
- one additional layer of abstraction decreases the speed (theoretically)
- Do you use an ORM/ODM (e.g. Mongoose)? Which one? Why?
Hi! I'm Michael 👋 I'm a Mentor & Senior Web Developer - I help you to reach your (career) goals.