How to get multiple result sets by calling a stored procedure using sequelize?
See original GitHub issueI noticed someone asked the same question, but not answered. Want to try this question here. To help understanding my question, the code below is an example to call stored procedure using sequelize:
sequelize.query(CALL GetLatestNews();
,
{
type: sequelize.QueryTypes.RAW
})
.then(function(results) {
console.log(JSON.stringify(results));
})
The stored procedure returns 3 result sets. However, only the first result set being returned.
I tried to change the line .then(function(results) { to .spread(function(results, metadata) {
This time, results is holding only the first row of the first result set, while metadata holding the second row of the first result set.
Any help is highly appreciated!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Sequelize - MS SQL - Multiple result sets of stored procedure ...
We are using Sequelize with MS SQL to retrieve data by executing stored procedures. The stored procedure is executed as RAW query. Example:...
Read more >How to: Execute Stored Procedures Returning Multiple Result ...
This sample demonstrates how to execute stored procedures that return multiple result sets and materialize entities from each result set.
Read more >Raw Queries - Sequelize
By default the function will return two arguments - a results array, and an object ... Will get called for every SQL query...
Read more >node-mssql | Microsoft SQL Server client for Node.js
query (command, [callback]). Execute the SQL command. To execute commands like create procedure or if you plan to work with local temporary tables,...
Read more >How to retrieve multiple ResultSets from a stored procedure ...
And we have created a procedure named sampleProcedure which retrieves the contents of these two tables as shown below: mysql> DELIMITER // ; ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’ think so sequelize is having this kind of problem.
First you have to make sure that multipleStatements should be true. Next whenever your procedure is returning more than one result set, your code should look like this
I got multiple resultset into same results in array form using this.
For me entity is returning the merged result and not seperate arrays from SP. I am using nodejs, sequelize and sql server model.sequelize.query(‘AssetCountAsPerStatus’, { multipleStatements: true, type: model.sequelize.QueryTypes.SELECT }) .then(data => { console.log(‘data’, data); var res_1 = Object.keys(data[0]); var res_1_List = []; for (var i = 0; i < res_1.length; i++) { res_1_List.push(data[0][i]); }