2.0.1 • Published 3 years ago

@ckpack/pg-helper v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

pg-helper

A lightweight node-postgres build query utils.

Since node-postgres uses ordinal parameter query ($1, $2, etc), the variables need to have a clear order. Once too many parameters are used, it will be extremely troublesome. pg-helper allows you to build SQL easier, faster and safer.

Example

const {PgHelper} = require('@ckpack/pg-helper');  
const pgHelper = new PgHelper({
    host,
    user,
    password,
    database,
    port: 5432,
    max: 20,
    idleTimeoutMillis: 30000,
    connectionTimeoutMillis: 2000,
  },{
    logger: console,
    returning: true,
});

// in node-postgres
// pg.query(`SELECT * FROM ${tablename} WHERE field1 = $1 AND field2 = $2`, [field1, field2]);

// in pg-helper 
pgHelper.runSql(`SELECT * FROM ${tablename} WHERE field1 = {field1} AND field2 = {field2}`, {field1, field2});
// Still supports the following way
pgHelper.runSql(`SELECT * FROM ${tablename} WHERE field1 = $1 AND field2 = $2`, [field1, field2])

Demos

Documentation

2.0.1

3 years ago

2.0.0

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago