Anybody know what "params" is/are for the Loopback docs here:
https://docs.strongloop.com/display/public/LB/Executing+native+SQL
it says:
Executing native SQL
To execute SQL directly against your data-connected model, use the following:
dataSource.connector.execute(sql, params, cb);
or
dataSource.connector.query(sql, params, cb); // For 1.x connectors
Where: sql - The SQL string. params - parameters to the SQL statement. cb - callback function
That is an array of values of your SQL string params. For example if you have postgresql database and parametrized query like this:
select * from table where id = $1 or name = $2
then you have to provide parameter values to your function, so you will do something like this:
var query = "select * from table where id = $1 or name = $2";
var params = [82, "My name"];
ds.connector.execute(query, params, function(err, data){
if(err){
console.log( err);
}else{
console.log(data);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With