Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call stored procedure in strongloop

I am using MySQL and strongloop, 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.

like image 854
NG51214 Avatar asked Feb 08 '23 17:02

NG51214


1 Answers

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

  ABCModel.remoteMethod(
    'swap',
    {
      accepts: [
        {arg: 'old_abc', type: 'string'},
        {arg: 'new_abc', type: 'string'}
      ],
      returns: {arg: 'result', type: 'object'},
      http: {path: '/swap', verb: 'post'}
    }
  );
};
like image 117
Ejaz Avatar answered Feb 10 '23 23:02

Ejaz