I just want to ask which database module is better, PG or sequelize? I heard that sequelize has sometimes problem with transaction. Thanks
PostgreSQL requires the use of the pg (or pg-native) npm package. Read more about this here. According to pg's documentation, only pg >= 8.2 is compatible with Node 14. If you're trying to use Sequelize 6 in Node 14 or newer, use that version of pg.
PostgreSQL can be classified as a tool in the "Databases" category, while Sequelize is grouped under "Object Relational Mapper (ORM)". "Relational database" is the primary reason why developers consider PostgreSQL over the competitors, whereas "Good ORM for node. js" was stated as the key factor in picking Sequelize.
As you can see there are many pros of using Sequelize as your ORM and it contains rich documentation as well. So, If you are looking for a stable ORM for your project sequelize is one of the best out of all.
PG is a raw driver - it simply allows us to send queries to database, and sequelize is an ORM (object relation mapper - https://en.wikipedia.org/wiki/Object-relational_mapping) - the high level module, that maps objects to database entries.
The usage of any of them depends on the scale of the project.
If project is a 100 line of codes utility - I prefer raw driver.
If project is quite big and have to be scalable and maintainable - I think sequelize
is better.
Also using sequelize
with very few changes in code you can change the database you use - from postgresql to mysql/sqlite.
It is worth noting, that you can use both modules in the same project - in part depending on transaction you can use pg
, and sequelize
for other parts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With