如何在strongloop中调用存储过程

时间:2021-11-07 16:38:36

I am using MySQL and strongloop, I have a stored procedure to swap data

我正在使用MySQL和strongloop,我有一个存储过程来交换数据

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.

我无法在文档中找到调用存储过程的任何示例。如何调用这个存储过程?提前谢谢。

2 个解决方案

#1


2  

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

#2


2  

Refer this link. dataSource.connector.execute(sql, params, cb); or dataSource.connector.query(sql, params, cb);

请参考这个链接。dataSource.connector。执行(sql、参数、cb);或dataSource.connector。查询(sql、参数、cb);

https://docs.strongloop.com/display/public/LB/Database+connectors https://docs.strongloop.com/display/public/LB/Executing+native+SQL

https://docs.strongloop.com/display/public/LB/Database +连接器https://docs.strongloop.com/display/public/LB/Executing +本地+ SQL

 module.exports = function(DemoModel) {
    var server = require('../../server/server');
      var ds = server.dataSources.MySQL;

    DemoModel.list = function(optionalparam, cb) {  


      var sql = 'select * from DemoModel';
      ds.connector.execute(sql, function(err, data)
      {
      if(err) return err;
      console.log(err);
      console.log("data",data);
        cb(null, data);
      });

    }

    DemoModel.remoteMethod(
        'list', 
        {
          accepts: {arg: 'param', type: 'string'},
          returns: {arg: 'result', type: 'object'},
          http: {path: '/list', verb: 'get'}
        }
    );


    };

#1


2  

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

#2


2  

Refer this link. dataSource.connector.execute(sql, params, cb); or dataSource.connector.query(sql, params, cb);

请参考这个链接。dataSource.connector。执行(sql、参数、cb);或dataSource.connector。查询(sql、参数、cb);

https://docs.strongloop.com/display/public/LB/Database+connectors https://docs.strongloop.com/display/public/LB/Executing+native+SQL

https://docs.strongloop.com/display/public/LB/Database +连接器https://docs.strongloop.com/display/public/LB/Executing +本地+ SQL

 module.exports = function(DemoModel) {
    var server = require('../../server/server');
      var ds = server.dataSources.MySQL;

    DemoModel.list = function(optionalparam, cb) {  


      var sql = 'select * from DemoModel';
      ds.connector.execute(sql, function(err, data)
      {
      if(err) return err;
      console.log(err);
      console.log("data",data);
        cb(null, data);
      });

    }

    DemoModel.remoteMethod(
        'list', 
        {
          accepts: {arg: 'param', type: 'string'},
          returns: {arg: 'result', type: 'object'},
          http: {path: '/list', verb: 'get'}
        }
    );


    };