I just want to ask which database module is better, PG or sequelize? I heard that sequelize has sometimes problem with transaction. Thanks
-
1Sequelize isn't a database module, it's an ORM, which relies on PG to work. – Ben Fortune Oct 24 '14 at 15:12
2 Answers
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

- 303
- 2
- 14

- 6,680
- 4
- 27
- 42
Sequelize
supports two kinds of transaction, managed and unmanaged transaction. In unmanaged transactions, user manually defines committing and rolling back by calling sequelize
methods. In managed transactions, sequelize
automatically rollback the transaction in case of an error.
As for node-postgres
and sequelize
are concerns. Here are some of pros and cons.
node-progress
:
- Pros:
- It's simple and lightweight library that sends queries directly to the database.
- Cons:
- It doesn't provide high-level abstractions like an ORM does.
Sequelize
:
- Pros:
- It provides high level abstractions which make it easier to work with the databases.
- It allows to change a database you use with a very few changes in the code.
- Cons:
- It has steeper learning curve than using a simple raw driver like
node-postgress
.
- It has steeper learning curve than using a simple raw driver like
Hope this helps.

- 21
- 6