Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 317
Pushker Yadav Avatar asked Apr 17 '15 12:04

Pushker Yadav


1 Answers

Your code looks correct.

But if you want a nicer syntax, example with pg-promise:

// calling a function:
const result = await db.func('funcName', [userName]);
//=> SELECT * FROM funcName('user-name')

// calling a stored procedure:
const result = await db.proc('procName', [userName]);
//=> CALL procName('user-name')
like image 163
vitaly-t Avatar answered Sep 19 '22 20:09

vitaly-t