postgres-wrapper
v1.0.4
Published
Postgres simple wrapper
Downloads
2
Readme
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()