1.0.4 • Published 4 years ago

postgres-wrapper v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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()
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago