2.1.1 • Published 5 years ago

@hafdon/pghelper v2.1.1

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

pghelper

wrapper on pg to help with managing postgres pools and multiple configs

install

npm i @hafdon/pghelper

use

const { poolmanager } = require('pghelper');
const { configure, cxn } = poolmanager;

const db = 'your_chosen_name_for_connection_1';
// rename the db prop `configOptions`
const { [db]: configOptions } = require('./pgconnection_examples.config.js');
const log = require('debug')('pghelper');

async function main() {
    await configure(db, configOptions);

    let results = await cxn({
        text: `select * from bird_table limit 1;`, // required
        values: [], // optional
        db, // required
    });

    if (results._error) {
        // TODO: handle error
        log('TODO: handle error');
    }
    log(results);
    /* pghelper: 
    { 
        _error: false,
        error: null,
        rows: [
            {
                id: 1,
                name: 'Finch',
                flying_ability: 17
            }
        ],
        length: 1,
        response : Object [Postgres Response Object]
    }
    */
}

main();

api

configure

  • synchronous function

proper type validation for config files

// pgconnection_examples.config.js
module.exports = {
    your_chosen_name_for_connection_1: [
        {
            protocol: 'postgres',
            host: 'host.com',
            user: 'user1',
            password: 'password1',
            database: 'db',
            schema: 'public',
            search_path: 'public',

            ssl: true,
            port: 1032,
            max: 5,
        },
        {
            protocol: 'postgres',
            host: 'host.com',
            user: 'user2',
            password: 'password2',
            database: 'db',
            schema: 'public',
            search_path: 'public',

            ssl: true,
            port: 1032,
            max: 5,
        },
    ],
    your_chosen_name_for_connection_2: [
        {
            protocol: 'postgres',
            host: 'another.host.com',
            user: 'user3',
            password: 'password3',
            database: 'db',
            schema: 'public',
            search_path: 'public',

            ssl: true,
            port: 1032,
            max: 5,
        },
    ],
};
2.1.1

5 years ago

2.1.0

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.10.0

5 years ago

1.9.1

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.13

5 years ago

1.4.12

5 years ago

1.4.11

5 years ago

1.4.10

5 years ago

1.4.9

5 years ago

1.4.8

5 years ago

1.4.7

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.3.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago