A
A
Alex Wells2015-11-08 21:03:03
ORM
Alex Wells, 2015-11-08 21:03:03

Synchronous ORM Node js?

Greetings. Generally such a problem. There is an entry in the database about the user, as well as ORM Sequelize. I'm trying to get this ORM to work in sync because promises don't work for me. Is this even possible, or will you have to abandon the ORM and use fucking raw queries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2015-11-08
@Alex_Wells

I'm trying to get this ORM to work in sync.... Is it even possible.... ?

In principle, you can get a code that looks like a synchronous code based on generators . You can take the co library and, based on it, get something like:
co(function* () {
  var user = yield User.find(id=5);
  some_manipulations_with_user(user);
  yield user.save();
  ...
});
The code is not working, just a demonstration of the idea.
You can read more in the book Node.js Design Patterns chapter 2, section - generators. Although judging by your question, you most likely need to study the entire chapter 2 from the beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question