Skip to content

Commit 7740b04

Browse files
committed
Document client.escapeIdentifier and client.escapeLiteral
Per brianc#1978 it seems that these client APIs are undocumented. Added documentation for these functions along with some examples and relevant links.
1 parent 48f4398 commit 7740b04

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: docs/pages/apis/client.mdx

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: pg.Client
33
---
4+
import { Alert } from '/components/alert.tsx'
45

56
## new Client
67

@@ -256,6 +257,28 @@ client
256257

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

260+
## client.escapeIdentifier
261+
262+
Escapes a string as a [SQL identifier](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS).
263+
264+
```js
265+
const escpaedIdentifier = client.escapeIdentifier('FooIdentifier');
266+
console.log(escpaedIdentifier); // '"FooIdentifier"'
267+
```
268+
269+
## client.escapeLiteral
270+
271+
Escapes a string as a [SQL literal](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS).
272+
273+
<Alert>
274+
**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.
275+
</Alert>
276+
277+
```js
278+
const escapedLiteral = client.escapeLiteral("hello \\ ' world");
279+
console.log(escapedLiteral); // " E'hello \\\\ '' world'"
280+
```
281+
259282
## events
260283

261284
### error

0 commit comments

Comments
 (0)