本文介绍了使用 MSSQL 使用输入参数调用存储过程的 Sequelize 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下代码的错误,无法找到通过 sequelize 调用 MSSQL 存储过程的语法的准确信息.我也尝试过类似 CALL spcName(param1, ...)

I'm getting an error for the code below and cannot find accurate information for the syntax to call a MSSQL store procedure through sequelize. I have also tried the syntx from the other posts on stackoverflow similar to CALL spcName(param1, ...)

错误:

(node:14580) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SequelizeDatabaseError: Incorrect syntax near '@param1'.

代码:

await sequelize.query('CALL spcName(@param1, @param2, @param3, @param4);', [value1, value2, value3, value4])

推荐答案

代码看起来像这样并且适用于 MSSQL.由于格式原因想要显示日期示例:

Code looks like this and works for MSSQL. Wanted to show date example because of formatting:

return await sequelize.query('scpTest :inDate', {replacements: {inDate: moment().subtract('d', 4).toISOString(), type: sequelize.QueryTypes.SELECT}

按照问题示例:

await sequelize.query('spcName :param1, :param2, :param3, :param4)', {replacements: {param1: value, param2: value, param3: value, param4: value}, type: sequelize.QueryTypes.SELECT})

这篇关于使用 MSSQL 使用输入参数调用存储过程的 Sequelize 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 08:54