使用多个参数在Loopback远程方法中执行Postgres存储过程

时间:2023-02-05 19:17:53

I'm trying to execute a stored procedure via a remote method on one my models. I'm able to execute very basic selects via custom SQL that utilize a single parameter, but can't seem to get an around an error passing multiple arguments into the proc. Here's the error and below a look at my code.

我正试图通过远程方法在我的模型上执行存储过程。我能够通过使用单个参数的自定义SQL执行非常基本的选择,但似乎无法解决将多个参数传递到proc中的错误。这是错误,下面是我的代码。

Anybody have any insight on what's causing this?

有人对导致这种情况的原因有什么了解吗?

[error: bind message supplies 1 parameters, but prepared statement "" requires 3]
name: 'error',
length: '130',
'severity': 'ERROR',
code: '08P01',
detail: undefined,
hint: undefined,
position: undefined,
...
file: 'postgres.c',
line: '1556',
routine: 'exec_bind_message' }

ScenarioAsvTarget.prepopulate = function(prepopulate, cb) {
        var ds=ScenarioAsvTarget.dataSource;
        var sql = "SELECT PREPOPULATE_ASV_TARGET($1,$2,$3)";
        ds.connector.execute(sql,[prepopulate],function(err,targets) {
            if (err) console.error(err);
            console.info(targets);
            cb(err,targets);
        });     
    };

ScenarioAsvTarget.remoteMethod(
'prepopulate',
{
    http: {verb: 'post'},
    description: "Prepopulate target cloud infrastructure",
    accepts: [
              {arg: 'input_scenario_id', type: 'Number'},
              {arg: 'input_scenario_asv_id', type: 'Number'},
              {arg: 'input_user_id', type:'String'}
              ],
    returns: {arg: 'data', type: ['string'], root: true}
    }
);  

1 个解决方案

#1


0  

You need to pass the args separately.

你需要单独传递args。

ScenarioAsvTarget.prepopulate = function(input_scenario_id, input_scenario_asv_id, input_user_id, cb) {
    var ds = ScenarioAsvTarget.dataSource;
    var sql = "SELECT PREPOPULATE_ASV_TARGET ($1, $2, $3)";
    ds.connector.execute(sql, input_scenario_id, input_scenario_asv_id, input_user_id, function(err, targets) {
        if (err) console.error(err);
        console.info(targets);
        cb(err, targets);
    });     
};

ScenarioAsvTarget.remoteMethod(
    'prepopulate',
    {
        http: {verb: 'post'},
        description: "Prepopulate target cloud infrastructure",
        accepts: [
            {arg: 'input_scenario_id', type: 'Number'},
            {arg: 'input_scenario_asv_id', type: 'Number'},
            {arg: 'input_user_id', type:'String'}
        ],
        returns: {arg: 'data', type: ['string'], root: true}
    }
); 

#1


0  

You need to pass the args separately.

你需要单独传递args。

ScenarioAsvTarget.prepopulate = function(input_scenario_id, input_scenario_asv_id, input_user_id, cb) {
    var ds = ScenarioAsvTarget.dataSource;
    var sql = "SELECT PREPOPULATE_ASV_TARGET ($1, $2, $3)";
    ds.connector.execute(sql, input_scenario_id, input_scenario_asv_id, input_user_id, function(err, targets) {
        if (err) console.error(err);
        console.info(targets);
        cb(err, targets);
    });     
};

ScenarioAsvTarget.remoteMethod(
    'prepopulate',
    {
        http: {verb: 'post'},
        description: "Prepopulate target cloud infrastructure",
        accepts: [
            {arg: 'input_scenario_id', type: 'Number'},
            {arg: 'input_scenario_asv_id', type: 'Number'},
            {arg: 'input_user_id', type:'String'}
        ],
        returns: {arg: 'data', type: ['string'], root: true}
    }
);