4.1.4 • Published 5 years ago

smn-pg v4.1.4

Weekly downloads
21
License
ISC
Repository
github
Last release
5 years ago

Installation

npm install smn-pg

Use Example

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.


INPUTS

EXECUTES < v.4

EXECUTES >= v.4


Example Config

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

INPUTS

INPUT (parameter)

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);
    });

INPUTMANY (parameters)

pg.request()
    .inputMany('param1','param2','param3')
    .execute('procedureName', (err, data) => {
        if (err)
            return console.log(err);

        console.log(data);
    });

EXECUTES

EXECUTE (procedureName, callback)

Return list results

return pg.request()
    .execute('procedureName', (err, data) => {
        if (err)
            return console.log(err);

        console.log(data);
    });

EXECUTEONE (procedureName, callback)

Return single result

return pg.request()
    .executeOne('procedureName', (err, data) => {
        if (err)
            return console.log(err);

        console.log(data);
    });

ASYNC_EXECUTE (procedureName)

Return list results

return pg.request()
    .asyncExecute('procedureName');

ASYNC_EXECUTEONE (procedureName)

Return single result

return pg.request()
    .asyncExecuteOne('procedureName');

EXECUTES v.4 OR GREATER

ASYNC_EXEC(procedureName, transacion?)

return pg.request()
    .asyncExec('procedureName', transaction?);

ASYNC_EXEC_ONE(procedureName, transacion?)

return pg.request()
    .asyncExecOne('procedureName', transaction?);
4.1.4

5 years ago

4.1.3

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.9

6 years ago

3.0.8

6 years ago

3.0.7

6 years ago

3.0.6

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago