12

I just want to ask which database module is better, PG or sequelize? I heard that sequelize has sometimes problem with transaction. Thanks

1
  • 1
    Sequelize isn't a database module, it's an ORM, which relies on PG to work. Commented Oct 24, 2014 at 15:12

2 Answers 2

38

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.