what is best/right way to call postgres function or stored procedure from nodejs

I am using "pg" module to handle with postgresql db ,what how to call function using pg i have doubt,

I am calling function using query method,

client.query("SELECT * FROM SQSP_IsUserNameExists($1)",[userName], function(err, result) {
  // some code.

});

that is working fine, but is this right way to call postgresql functions.


Your code looks correct.

But if you want a nicer syntax, the same example via pg-promise:

db.func('SQSP_IsUserNameExists', userName)
    .then(data => {
        // data as returned from the function
    })
    .catch(error => {
        // error
    });

From the PostgrSQL side, if the function returns a result set than yes the SQL is syntax is correct. As for the Node call syntax I am not familiar with that framework. But if its returning results then I say task complete.

链接地址: http://www.djcxy.com/p/84532.html

上一篇: 定位在绝对定位的div下面

下一篇: 从nodejs调用postgres函数或存储过程的最佳/正确方法是什么?