Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling stored procedures in Sequelize.js

I have searched documentation and tried google that, but I did not find a straight answer to the question:

How can I call a stored procedure in Sequelize?

I have searched the documentation of Sequelize but I have even not found a trace of the word "procedure" in that.

The closest I got was this bug-report-turned-feature-request: https://github.com/sequelize/sequelize/issues/959

Quoting from the link:

What I imagine would be awesome:

sequelize.query('CALL calculateFees();').success(
    function (settingName1, settingName2, settingName3, users) {
});

They mention that it is possible to call stored procedures, but the syntax is not provided.

Can anyone give me an example with the proper syntax?

Thanks.

like image 412
atoth Avatar asked Mar 26 '15 14:03

atoth


2 Answers

Call SP with parameters in Sequelize

sequelize
  .query('CALL login (:email, :pwd, :device)', 
        {replacements: { email: "[email protected]", pwd: 'pwd', device: 'android', }})
  .then(v=>console.log(v));
like image 93
Nishchit Avatar answered Sep 23 '22 07:09

Nishchit


Change success to spread and you're good to go. Note that this will only work on sequlize 2.0

like image 37
Jan Aagaard Meier Avatar answered Sep 22 '22 07:09

Jan Aagaard Meier