# pg-connect

> Create a postgres connection and ensure it get's closed

Latest version **2.0.2** (published 2016-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install pg-connect
pnpm add pg-connect
yarn add pg-connect
bun add pg-connect
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2016-08-29 |
| First published | 2015-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mike Atkins |
| Maintainers | apechimp, lanetix-system |
| Keywords | pg, postgres, promise, connection, transaction |

## Links

- npm: https://www.npmjs.com/package/pg-connect
- Repository: https://github.com/lanetix/node-pg-connect
- Issues: https://github.com/lanetix/node-pg-connect/issues
- npm.io page: https://npm.io/package/pg-connect

## Dependencies (2)

- [pg](https://npm.io/package/pg.md) ^6.0.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.0.5

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2016-08-29
- 2.0.1 — 2015-11-20
- 2.0.0 — 2015-11-17
- 1.1.0 — 2015-08-11
- 1.0.0 — 2015-07-17

## README

DEPRECATED
==========

As of [pg@6](https://github.com/brianc/node-postgres/blob/master/CHANGELOG.md#v600), node-postgres has promise suport out of the box. Do not use this package. It is no longer maintained!

pg-connect
==============
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![Circle CI](https://circleci.com/gh/lanetix/node-pg-connect.svg?style=svg)](https://circleci.com/gh/lanetix/node-pg-connect)
[![Dependency Status](https://david-dm.org/lanetix/node-pg-connect.svg)](https://david-dm.org/lanetix/node-pg-connect)

Connect to a postgres database with a promise api. Pretty much just an implementation of the suggestions in [the bluebird api](http://bluebirdjs.com/docs/api/disposer.html) 

Installation
------------
[![npm install --save pg-connect](https://nodei.co/npm/pg-connect.png)](https://npmjs.org/package/pg-connect)

Usage
-----

```javascript
var Promise = require('bluebird')
var getConnection = require('pg-connect')(connectionString)

Promise.using(
  getConnection(),
  function (query) {
    return query('SELECT * from foo')
  }
).
then(function (results) {
  // ... use the results
})
```

where query is a promisified version of [`client.query`](https://github.com/brianc/node-postgres/wiki/Client#method-query-simple) in [pg](https://github.com/brianc/node-postgres).

An example with transactions:

```javascript
var Promise = require('bluebird')
var getConnection = require('pg-connect')(connectionString)

getConnection.withTransaction(function (query) {
  return query('SELECT * from foo')
}).
then(function (results) {
  // ... use the results
})
```

Also, `getConnection.end` is equivalent to [`pg.end`](https://github.com/brianc/node-postgres/wiki/pg#end). Similarly, `getConnection.defaults` is equivalent to [`pg.defauts`](https://github.com/brianc/node-postgres/wiki/pg#pgdefaults).

Testing
-------

1. Ensure you have a local postgres database named `pg_connect_test` or export
   `DATABASE_URL` pointing to a database.
2. `npm test`

---
_Source: https://npm.io/package/pg-connect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
