postgres-wrapper

1.0.4 • Public • Published

postgres-wrapper

Postgres simple wrapper service.

Install

$ npm install postgres-wrapper

Usage

Before use you need to set environment variables:

  • NODE_ENV (Node environment: development, production, etc..)
  • POSTGRES_URL (Url to connnecto to postgres: postgres://username:password@url:port/db)
const pg = require('postgres-wrapper')

// Get one record from db
async function run () {
  const id = 1
  const query = `
    SELECT *
    FROM data
    WHERE id = $1`
  const params = [id]
  const object = await pg.one({ query, params }) // return one record in object
  const object = await pg.oneOrNone({ query, params }) // return one or none record
  const array = await pg.any({ query, params }) // return one or many record in array
  const array = await pg.many({ query, params }) // return many records in array
  await pg.none({ query, params }) // no returning any record
  await pg.end() // end postgress connection
}

run()

Package Sidebar

Install

npm i postgres-wrapper

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

3.57 kB

Total Files

4

Last publish

Collaborators

  • stasandk