npm install smn-pg
require('smn-pg')(config);
Only works on Node v6 and above.
Async methods, only works on Node v7 and above.
Check the operation list below.
let config = {
user: 'user',
database: 'database',
password: 'pass',
host: 'host',
port: 5432,
max: 10,
idleTimeoutMillis: 30000,
schema?: 'schema default'
};;
require('smn-pg')(config, { schema: 'Schema default' });
// SINGLE INSTANCE
Params - Value
/* Inform the params in the same sequency of prcedure */
pg.request()
.input('value')
.input('value')
.input('value')
.execute('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
Params - Name,Value
pg.request()
.input('paramName1','value1')
.input('paramName2','value2')
.execute('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
Params - Object,Prefix
let obj = {
parameterName: 'parameterValue',
parameterName1: 'parameterValue1',
parameterName2: 'parameterValue2',
}
/* The name of the attributes of the object must have the same name of the params. */
/* The object must never have more attributes than params expected by the procedure */
/* In the case have a prfix default, he can be past in the second params of the method */
pg.request()
.input(obj, /*Optional prefix name*/)
.input('paramName','value') /* Optional together with object */
.execute('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
pg.request()
.inputMany('param1','param2','param3')
.execute('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
Return list results
return pg.request()
.execute('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
Return single result
return pg.request()
.executeOne('procedureName', (err, data) => {
if (err)
return console.log(err);
console.log(data);
});
Return list results
return pg.request()
.asyncExecute('procedureName');
Return single result
return pg.request()
.asyncExecuteOne('procedureName');
return pg.request()
.asyncExec('procedureName', transaction?);
return pg.request()
.asyncExecOne('procedureName', transaction?);