Skip to content

Commit

Permalink
Document client.escapeIdentifier and client.escapeLiteral
Browse files Browse the repository at this point in the history
Per brianc#1978 it seems that these client APIs are undocumented. Added documentation for these functions along with some examples and relevant links.
  • Loading branch information
TheConner committed Apr 10, 2023
1 parent 48f4398 commit 7740b04
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/pages/apis/client.mdx
@@ -1,6 +1,7 @@
---
title: pg.Client
---
import { Alert } from '/components/alert.tsx'

## new Client

Expand Down Expand Up @@ -256,6 +257,28 @@ client

_note: end returning a promise is only available in pg7.0 and above_

## client.escapeIdentifier

Escapes a string as a [SQL identifier](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS).

```js
const escpaedIdentifier = client.escapeIdentifier('FooIdentifier');
console.log(escpaedIdentifier); // '"FooIdentifier"'
```

## client.escapeLiteral

Escapes a string as a [SQL literal](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS).

<Alert>
**Note**: Instead of manually escaping SQL literals, it is recommended to use parameterized queries. Refer to [parameterized queries](/features/queries#parameterized-query) and the [client.query](#clientquery) API for more information.
</Alert>

```js
const escapedLiteral = client.escapeLiteral("hello \\ ' world");
console.log(escapedLiteral); // " E'hello \\\\ '' world'"
```

## events

### error
Expand Down

0 comments on commit 7740b04

Please sign in to comment.