# simple-pg-client

> Simplified Javascript PostgreSQL client.

Latest version **1.1.0** (published 2022-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-pg-client
pnpm add simple-pg-client
yarn add simple-pg-client
bun add simple-pg-client
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-08-16 |
| First published | 2022-07-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 63.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | samhuk |

## Links

- npm: https://www.npmjs.com/package/simple-pg-client
- Repository: https://github.com/samhuk/simple-pg-client
- Homepage: https://github.com/samhuk/simple-pg-client#readme
- Issues: https://github.com/samhuk/simple-pg-client/issues
- npm.io page: https://npm.io/package/simple-pg-client

## Dependencies (1)

- [pg](https://npm.io/package/pg.md) ^8.7.3

## Recent versions

- 1.1.0 (latest) — 2022-08-16
- 1.0.5 — 2022-08-13
- 1.0.4 — 2022-08-02
- 1.0.3 — 2022-07-31
- 1.0.2 — 2022-07-31
- 1.0.1 — 2022-07-21
- 1.0.0 — 2022-07-21

## README

# simple-pg-client

Wrapper around [pg](https://www.npmjs.com/package/pg) that provides connection retrying, automatic database creation, and a simpler cut-down query interface, with optional access to the underlying `pg` client.

## Usage

`npm i --save simple-pg-client`

Basic usage:

```typescript
import { createSimplePgClient } from 'simple-pg-client'

const provision = async () => {
  // Connect to DB
  const db = await createSimplePgClient({
    host: 'localhost',
    port: 5432,
    user: 'postgres',
    password: 'postgres',
    db: 'my-app-store-prod',
  })
  const db = await createProdAppStoreDbService()
  // Query and return the full default `pg` client query response
  await db.query('create table "user"')
  // Query and return first row
  const userRow = await db.queryGetFirstRow('insert into "user" (id, name) values (1, "user1")')
  // Query and return all rows
  const userRows = await db.queryGetRows('select * from "user"')
}
```

Full options:

```typescript
import { createSimplePgClient } from 'simple-pg-client'

export const createProdAppStoreDbService = () => createSimplePgClient({
  host: 'localhost',
  port: 5432,
  user: 'postgres',
  password: 'postgres',
  db: 'my-app-store-prod',
  extensions: ['uuid-ossp'],
  retryIntervalExpression: retryIndex => (retryIndex + 1) * 2,
  createDbIfNotExists: true,
  maxNumRetry: 2,
  schemaName: 'public',
  sqlLoggingTruncation: 200,
  createDbSqlTemplate: `CREATE DATABASE {db}
WITH
OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;`,
  maintenanceDbOptions: {
    db: 'postgres',
    maxNumRetry: 10,
    user: 'postgres',
    password: 'postgres',
  },
  additionalPgOptions: {
    query_timeout: 5000,
  },
  events: {
    // ...
    onDbConnect: (client, message) => console.log(message),
    // ...
  }
})
```

See the Typescript JSDocs for descriptions of the options.

## Development

`npm i`

`npm start` - Start a hot-reloading tsc build.

`npm run check` - Run linting, unit tests, and a tsc build.

## Notable Technologies

* typescript
* jest
* eslint

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