# psychopiggy

> Psychopiggy is a thin wrapper around the excellent 'pg' module.

Latest version **3.0.1** (published 2021-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install psychopiggy
pnpm add psychopiggy
yarn add psychopiggy
bun add psychopiggy
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2021-10-31 |
| First published | 2018-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jeswin Kumar |
| Maintainers | jeswin |

## Links

- npm: https://www.npmjs.com/package/psychopiggy
- Repository: https://github.com/jeswin/psychopiggy
- Homepage: https://github.com/jeswin/psychopiggy#readme
- Issues: https://github.com/jeswin/psychopiggy/issues
- npm.io page: https://npm.io/package/psychopiggy

## Dependencies (4)

- [pg](https://npm.io/package/pg.md) ^8.7.1
- [@types/pg](https://npm.io/package/@types/pg.md) ^8.6.1
- [pg-params](https://npm.io/package/pg-params.md) ^2.0.2
- [@types/node](https://npm.io/package/@types/node.md) ^16.11.6

## Recent versions

- 3.0.1 (latest) — 2021-10-31
- 3.0.0 — 2021-09-25
- 2.0.8 — 2021-04-05
- 2.0.7 — 2021-03-28
- 2.0.6 — 2021-03-25
- 2.0.5 — 2020-08-13
- 2.0.4 — 2020-07-17
- 2.0.3 — 2020-05-02
- 2.0.2 — 2019-06-21
- 2.0.1 — 2019-06-21
- 2.0.0 — 2019-06-21
- 1.0.3 — 2019-05-23
- 1.0.2 — 2019-05-10
- 1.0.1 — 2019-04-15
- 1.0.0 — 2019-04-15
- … 3 more at https://npm.io/package/psychopiggy/versions

## README

# psychopiggy

Psychopiggy is a thin wrapper around the excellent 'pg' module.

Adds these features:

- Named parameters
- Releases clients automatically
- Avoids transaction boilerplate

## Installation

```bash
npm install psychopiggy
```

## Usage

Here's how to run a simple query

```js
import * as pg from "psychopiggy";

// connection config
const config = {
  database: "dbname",
  host: "hostname",
  user: "dbusername",
  password: "password",
  port: 5432
};

// Using pools.
async function createAccount() {
  pg.createPool(config);
  const pool = pg.getPool(config);
  const { rows } = await pool.query(
    `INSERT INTO account (
    username, password, email) VALUES ('jeswin', 'secretive', 'jeswin@example.com')`
  );
}
```

A simple Select query

```js
async function getUsers() {
  const pool = pg.getPool(config);
  const params = new pg.Params({
    username: "jeswin"
  });
  const { rows } = await pool.query(
    `SELECT * FROM "appusers" WHERE username=${params.id("username")}`,
    params.values()
  );
}
```

Insert Statements

```js
async function createAccount() {
  const pool = pg.getPool(config);
  const params = new pg.Params({
    email: "jeswin@example.com",
    password: "secretive",
    username: "jeswin"
  });
  const { rows } = await pool.query(
    `INSERT INTO account (${params.columns()}) VALUES (${params.ids()})`,
    params.values()
  );
}
```

Transactions. If there's an exception, everything within the transaction is rolled back automatically.

```js
async addTwoUsers() {
  pg.createPool(config);

  const pool = pg.getPool(config);

  await pg.withTransaction(async client => {
    await client.query(`INSERT INTO account (
      username, password, email) VALUES ('user1', 'secretive1', 'user1@example.com')`);
    await client.query(`INSERT INTO account (
      username, password, email) VALUES ('user2', 'secretive2', 'user2@example.com')`);
  }, config);
}
```

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