Skip to content

Promise-based wrapper for `node-postgres` library designed for easy use with ES7 async/await.

License

Notifications You must be signed in to change notification settings

kriasoft/node-pg-client

Repository files navigation

ES7 Async/Await Client for PostgreSQL

NPM version NPM downloads Build Status Dependency Status DevDependency Status

Promise-based wrapper for node-postgres library designed for easy use with ES7 async/await.

How to Install

$ npm install pg-client --save

Getting Started

Usage sample in a Node.js/Express web app:

import db from 'pg-client';
import { Router } from 'express';
import { connectionString } from '../config';

const router = new Router();

router.get('/users', (req, res, next) => {
  db.connect(connectionString, async ({ query }) => {
    const result = await query('SELECT id, email FROM users WHERE id = $1', 123);
    if (result.rowCount) {
      res.send(result.rows[0]);
    } else {
      res.sendStatus(404);
    }
  }).catch(next);
});

export default router;

Related Projects

License

The MIT License © 2016 Kriasoft, LLC. All rights reserved. Made with ♥ by Konstantin Tarkus (@koistya) and contributors

About

Promise-based wrapper for `node-postgres` library designed for easy use with ES7 async/await.

Resources

License

Stars

Watchers

Forks

Packages

No packages published