# pg-do

> The client for postgres

Latest version **1.0.4** (published 2017-09-21) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.0.4 |
| Published | 2017-09-21 |
| First published | 2017-09-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tree Xie |
| Maintainers | tree.xie |
| Keywords | pg, postgres |

## Links

- npm: https://www.npmjs.com/package/pg-do
- npm.io page: https://npm.io/package/pg-do

## Dependencies (3)

- [pg](https://npm.io/package/pg.md) ^7.3.0
- [debug](https://npm.io/package/debug.md) ^3.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Recent versions

- 1.0.4 (latest) — 2017-09-21
- 1.0.3 — 2017-09-20
- 1.0.2 — 2017-09-19
- 1.0.1 — 2017-09-18
- 1.0.0 — 2017-09-18

## README

# pg-do

[![Build Status](https://travis-ci.org/vicanso/pg-do.svg?branch=master)](https://travis-ci.org/vicanso/pg-do)
[![Coverage Status](https://img.shields.io/coveralls/vicanso/pg-do/master.svg?style=flat)](https://coveralls.io/r/vicanso/pg-do?branch=master)
[![npm](http://img.shields.io/npm/v/pg-do.svg?style=flat-square)](https://www.npmjs.org/package/pg-do)
[![Github Releases](https://img.shields.io/npm/dm/pg-do.svg?style=flat-square)](https://github.com/vicanso/pg-do)

## API

### Client

```js
const PG = require('pg-do');
const client = new PG('postgres://test:123456@127.0.0.1:5432/test?max=20&idleTimeout=5000');
client.on('acquire', () => console.info('acquire'));
client.on('remove', () => console.info('remove'));
client.on('error', () => console.info('error'));
client.on('connect', () => console.info('connect'));
```

### getTable

Get the table instance

```js
const userSchema = {
  account: 'varchar(80) unique',
  createdAt: 'varchar(24) NOT NULL',
  email: 'varchar(160)',
  age: 'smallint CHECK (age > 0)',
};
client.addSchema('users', userSchema);
const users = client.getTable('users');
```

#### Table.insert

Insert the data to table


```js
const user = await users.insert({
  account: 'vicanso',
  email: 'vicansocanbico@gmail.com',
  age: 30,
}, 'account createdAt');


const arr = await users.insert([
  {
    account: 'a',
  },
  {
    account: 'b',
  },
], 'account');
```

#### Table.count

Count the data

```js
const count = await users.count({
  account: 'vicanso',
});

const total = await users.count({});
```

#### Table.findOne

Find one record

```js
const user = await users.findOne({});

const user = await user.findOne({
  age: 20,
});
```

#### Table.find

Find records

```js
const data = await users.find({});
```

## LICENSE

ISC

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