Advantages of using Sequelize over other alternatives
There are many alternative ways of querying the database from your application. There are ORMs, DAOs, raw database drivers, and so on. Each methodology has its pros and cons and caters to different programming styles and conventions. Typically, those who favor convention over configuration tend to gravitate toward ORMs, while those who favor configuration tend to use DAO frameworks or raw database drivers.
An ORM can handle data validation, similar to DAOs, with additional features such as reading and writing from a database using a driver. With ORMs, you would not need to manage query statements manually, which could save you time over the DAO or raw connection methods.
Note
An ORM is not mutually exclusive to DAOs. You can think of DAOs as being explicit as opposed to being implicit and presumptuous. A DAO only provides an interface for your data. It does not involve how/where you read or write the data (the database driver), nor will it concern itself with the data’s integrity unless the application manually invokes some form of data validation outside of the DAO’s scope.
When using an ORM such as Sequelize, you will have the following features without any additional code:
- Transaction handling
- Connection pooling
- Model/data validation
- Data integrity (outside of DBMS’ scope of foreign keys (FKs), unique constraints, and so on)
- Eager loading
- Schematic migration and cascading
- Optimistic locking
Using a DAO or a raw database driver will forfeit these features, and you will have to build these solutions yourself. Using an ORM such as Sequelize will help you build your project with more efficiency and efficacy.
So far, we have covered the what and why for Sequelize; now, we will be going over the how for installing the necessary prerequisites for our application.