2

I'm recently learning all specs of this powerful ORM, like migrating tables, define schemas, define models, associations, inserts, etc.

My particular question is How manage Postgres Stored Procedures (SP) in sequelize?

I'm using Node.js for my server.

1 Answers1

7

You can use:

sequelize.query('CALL yourStoredProcedure();')
  .then(data => {
    // success ...
  }).catch(error => {
    // error ...
  });

Update (2017)

You can also use this with ES2017 syntax:

try {
  let data = await sequelize.query('CALL yourStoredProcedure();');
  // success ...
} catch (error) {
  // error ...
}

Note that you need to be inside a function declared with the async keyword.

The second syntax works in Node v7.0+ with the harmony flag and v7.6+ without any flags. See:

See the updates to this answer for more info:

rsp
  • 107,747
  • 29
  • 201
  • 177