GithubHelp home page GithubHelp logo

Stored Procedures about tedious HOT 8 CLOSED

tediousjs avatar tediousjs commented on July 18, 2024
Stored Procedures

from tedious.

Comments (8)

pekim avatar pekim commented on July 18, 2024 1
var TYPES = require('tedious').TYPES;

var request = new Request('my_proc', function(err) {
    ....
});

var string = 'some text';
var number = 7;

request.addParameter(TYPES.VarChar, 'parameterName', string);
request.addParameter(TYPES.Int, 'anotherParameterName', number);
request.addOutputParameter(TYPES.VarChar, 'outputParameterName', {length: 10});    // varchar(10)

request.on('returnValue', function(parameterName, value, metadata) {
    console.log(parameterName + ' = ' + value);      // outputParameterName = ...
});

connection.callProcedure(request);

Note: I am not convinced that the API is quite right. There's a good chance that it will change.

from tedious.

pekim avatar pekim commented on July 18, 2024 1

Please note, the first two arguments to the Request.addParameter and Request.addOutputParameter functions have been swapped around. The first argument is now the parameter name.

request.addParameter('parameterName', TYPES.VarChar, string);
request.addParameter('anotherParameterName', TYPES.Int, number);

from tedious.

pekim avatar pekim commented on July 18, 2024

It should be possible to call stored procedures now, but in a quite limited way. If you don't need any output parameters, then you can use a Request to execute a statement that just happens to be a stored procedure.

For example, sp_who accepts no parameters, and outputs a result set. So it can be treated the same as the execution of any select statement.

Input parameters can passed using string concatention.

var sql = "exec my_proc @myParam = '" + value + "'";
new Request(sql, ...)

Of course this is horrible, and not a good strategy. Issue #14 will introduce support for execution of parameterised requests, which will remove the need for that approach. I intend to work on it soon, and expect it to be in the next release. It will only support a small number of data types for parameters intially.

Once parameterised requests are in place, it shouldn't require too much work to provide a decent API for execution of stored procedures.

from tedious.

jschuhr avatar jschuhr commented on July 18, 2024

I don't mind running "exec my_proc" strings as SQL statements; it seems to work except the row count comes back undefined in these cases.

from tedious.

pekim avatar pekim commented on July 18, 2024

Support for executing stored procedures, including passing input and output parameters has been added.
So far only tinyint, smallint, int, varchar and nvarchar are supported.

The documentation has not been updated yet.

from tedious.

ReiGarcia avatar ReiGarcia commented on July 18, 2024

Could you post a sample code to call a stored procedure using input/output parameters?
Thanks.

from tedious.

ReiGarcia avatar ReiGarcia commented on July 18, 2024

Thanks!

from tedious.

pekim avatar pekim commented on July 18, 2024

Included in v0.0.4.

from tedious.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.