NG51214 NG51214 - 1 year ago 92
Javascript Question

How to call stored procedure in strongloop

I am using

, I have a stored procedure to swap data

swap_XYZ('<old_abc>', '<new_new>')

I am not able to find any example in the documentation to call stored procedure. How to call this stored procedure? Thanks in advance.

Answer Source
module.exports = function (ABCModel) {
 var ds = app.dataSources.dsMySQL;

  ABCModel.swap = function (old_abc, new_abc, cb) {

    var sql = "CALL `swap_XYZ`('" + old_abc + "','" + new_abc + "');";

    ds.connector.query(sql, function (err, data) {
      if (err) {
        console.log("Error:", err);
      cb(null, data);
      console.log("data:", data);

      accepts: [
        {arg: 'old_abc', type: 'string'},
        {arg: 'new_abc', type: 'string'}
      returns: {arg: 'result', type: 'object'},
      http: {path: '/swap', verb: 'post'}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download