question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get multiple result sets by calling a stored procedure using sequelize?

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
indrajeet0510commented, Sep 16, 2016

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

var query = "CALL someprocedure(:userId,:status)";
sequelize.query(query,{ replacements : { userId : userId, status : status}, type : sequelize.QueryTypes.SELECT}

I got multiple resultset into same results in array form using this.

0reactions
ghostcommented, Nov 5, 2019

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]); }

            var res_2 = Object.keys(data[1]);
            var res_2_List = [];
            for (var j = 0; j < res_2.length; j++) {
                res_2_List.push(data[1][j]);
            }
            return res.status(200).json({ "res_1_List": res_1_List, "res_2_List": res_2_List })
        })
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found