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, ...)
error:
(node:14580) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SequelizeDatabaseError: Incorrect syntax near '@param1'.
for code:
await sequelize.query('CALL spcName(@param1, @param2, @param3, @param4);', [value1, value2, value3, value4])
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}
Following the question example:
await sequelize.query('spcName :param1, :param2, :param3, :param4)', {replacements: {param1: value, param2: value, param3: value, param4: value}, type: sequelize.QueryTypes.SELECT})
You can try
await sequelize.query('CALL spcName(:params )', { replacements: {params : ['value1, value2, value3, value4']} })
Spartans
Use : to indicate parameter and replacements to map values. See example below.
async getPlayers(UserId: number, requestObject: any): Promise<any> {
this.sequelize = Server.sequelize;
try {
let o_rowcnt = 0;
let playersList = await this.sequelize.query('CALL sp_discovery (:p_user, :p_game, :p_platform, :p_headphone,:p_start,:p_end , :p_stanceId , @o_rowcnt )',
{
replacements: {
p_user: UserId,
p_game: requestObject.gameid,
p_platform: requestObject.platformid,
p_headphone: requestObject.headphone,
p_start: requestObject.index,
p_end: requestObject.limit,
p_stanceId: requestObject.stanceid
}
}
);
return playersList;
} catch (e) {
return e;
}
}
来源:https://stackoverflow.com/questions/42538525/sequelize-sytax-for-calling-stored-procedure-with-input-parameters-using-mssql