Creating models from stored procedures in MS SQL

627 views
Skip to first unread message

Clyde Lobo

unread,
Sep 26, 2014, 11:48:35 AM9/26/14
to loopb...@googlegroups.com
Hi,

I need to create models from existing stored procedures inside a SQL Server. I tried discovering them using the discover-api. But LB is not that advanced. Does any one know of ways/ solutions by which I can achieve the same?

Any links/hints/sample are welcome

Regards,
Clyde

Raymond Feng

unread,
Sep 26, 2014, 12:18:22 PM9/26/14
to Clyde Lobo, loopb...@googlegroups.com
You should be able to call SQL server stored procedure as follows:

1. Get the Connection object from app.dataSources.mssql.connector.client
2. Call mssql driver api:

var sql = require(‘mssql’);
var request = new sql.Request(connection);
    request.input('input_parameter', sql.Int, 10);
    request.output('output_parameter', sql.VarChar(50));
    request.execute('procedure_name', function(err, recordsets, returnValue) {
        // ... error checks

        console.dir(recordsets);
    }); 

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clyde Lobo

unread,
Sep 29, 2014, 5:49:12 AM9/29/14
to loopb...@googlegroups.com, clyde...@gmail.com
How do I get the app object?

Raymond Feng

unread,
Sep 29, 2014, 11:52:37 AM9/29/14
to Clyde Lobo, loopb...@googlegroups.com
The app object is available via:

1. require(‘server/server.js’)

2. Drop in a JS file under server/boot, for example:

module.exports = function(app) {
...
}

Thanks,

---
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

Clyde Lobo

unread,
Sep 29, 2014, 11:22:52 PM9/29/14
to loopb...@googlegroups.com
I should have specified this earlier,

I have created a remote methods in one of the models and trying to call the stored procedure. Whatever you have suggested does not work as the server module is not found. I tired creating a connection manually, but get the error that the connection has not been established.

Hope I have explained things clearly. Please feel free to ask for further details
Thanks, and sorry for the trouble.

Clyde Lobo

unread,
Oct 1, 2014, 7:21:16 AM10/1/14
to loopb...@googlegroups.com, clyde...@gmail.com
Hi,

I managed to get the connection object, its just one more level deep

   var connection = app.dataSources.mssql.connector.client.request;
  var request = connection();
request.execute('procedure_name', function(err, recordsets, returnValue) {
        // ... error checks

        console.dir(recordsets);
    }); 

Jason McGinnis

unread,
Feb 5, 2015, 4:20:34 PM2/5/15
to loopb...@googlegroups.com, clyde...@gmail.com
If I have used the commandline tool to generate models and api, can I update or override those models to use stored procedures?

Jason McGinnis

unread,
Feb 5, 2015, 4:43:52 PM2/5/15
to loopb...@googlegroups.com, clyde...@gmail.com
Let me clarify a little more of what my ultimate goal is.
I would like to use the StrongLoop framework to quickly get a project up and running.
I would generate the angular service script.
After everything is in place and working, I would like to do some performance tuning and point the models to crud stored procedures (that I have written or generated).
My vision is that the api broswer and everything else would not even know the difference.

Karen Piotrowski

unread,
Jun 16, 2015, 10:49:18 PM6/16/15
to loopb...@googlegroups.com
Hi! Where did you put that code? in a file inside the /server/boot directory?

And Where did you specified the database you are using for mssql? I mean, where's the datasource for this if you are using node-mssql instead of the loopback connector for mssql? Or are you using both?

Thank you!!

Michael DeMutis

unread,
Apr 18, 2018, 11:36:34 AM4/18/18
to LoopbackJS

OK so we can execute stored procedures.  I was able to get this working without issue.  How can I go one step further and create my model based on the stored proc?  Is this going to be possible?
Reply all
Reply to author
Forward
0 new messages