# pg-escape

> escape postgres queries which do not support stored procedures

Latest version **0.2.0** (published 2015-12-02) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-12-02 |
| First published | 2014-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/pg-escape) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 82 |
| Maintainers | tjholowaychuk |
| Keywords | pg, postgres, escape, query |

## Links

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

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2015-12-02
- 0.1.0 — 2015-04-13
- 0.0.3 — 2014-06-18
- 0.0.2 — 2014-03-18
- 0.0.1 — 2014-03-17

## README

# pg-escape

  Sprintf-style postgres query formatting and escape helper functions.

## Installation

```
$ npm install pg-escape
```

## Example

```js
var sql = escape('INSERT INTO %I VALUES(%L)', 'books', "O'Reilly");
console.log(sql);
```

yields:

```
INSERT INTO books VALUES('O''Reilly')
```

## API

### escape(fmt, ...)

 Format the given arguments.

### escape.string(val)

  Format as a simple string.

### escape.dollarQuotedString(val)

  Format as a [dollar quoted string](http://www.postgresql.org/docs/8.3/interactive/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING)

### escape.ident(val)

  Format as an identifier.

### escape.literal(val)

  Format as a literal.

## Formats

- `%s` formats the argument value as a simple string. A null value is treated as an empty string.
- `%Q` formats the argument value as a [dollar quoted string](http://www.postgresql.org/docs/8.3/interactive/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING). A null value is treated as an empty string.
- `%I` treats the argument value as an SQL identifier, double-quoting it if necessary. It is an error for the value to be null.
- `%L` quotes the argument value as an SQL literal. A null value is displayed as the string NULL, without quotes.
- `%%` In addition to the format specifiers described above, the special sequence %% may be used to output a literal % character.

# License

  MIT

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