node.js 在 Sequelize.js 中调用存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29280785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:33:46  来源:igfitidea点击:

Calling stored procedures in Sequelize.js

node.jssequelize.js

提问by atoth

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?

如何在 Sequelize 中调用存储过程?

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

我搜索了 Sequelize 的文档,但我什至没有在其中找到“程序”一词的踪迹。

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

我得到的最接近的是这个 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.

谢谢。

采纳答案by Jan Aagaard Meier

Change successto spreadand you're good to go. Note that this will only work on sequlize 2.0

更改successspread,您就可以开始了。请注意,这仅适用于 sequelize 2.0

回答by Nishchit Dhanani

Call SP with parameters in Sequelize

在 Sequelize 中使用参数调用 SP

sequelize
  .query('CALL login (:email, :pwd, :device)', 
        {replacements: { email: "[email protected]", pwd: 'pwd', device: 'android', }})
  .then(v=>console.log(v));

回答by Buhiire Keneth

sequalise queries return promises so below is how i query stored procedures.

sequalise 查询返回承诺,所以下面是我查询存储过程的方式。

sequelize.query('CALL calculateFees();').then(function(response){
     res.json(response);
    }).error(function(err){
       res.json(err);
});

回答by Josep1992

I executed the stored procedure with the EXEC Key word.

我用 EXEC 关键字执行了存储过程。

sequelize
.query('EXEC getData :@param1', { replacements: { @param1: 'Test'}, type:sequelize.QueryTypes.SELECT })
.then(data => /*Do something with the data*/)
.catch(error => /*Do something with the error*/)