Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 983 Bytes

utilities.mdx

File metadata and controls

30 lines (22 loc) · 983 Bytes
title
Utilities

import { Alert } from '/components/alert.tsx'

Utility Functions

pg.escapeIdentifier

Escapes a string as a SQL identifier.

const { escapeIdentifier } = require('pg')
const escapedIdentifier = escapeIdentifier('FooIdentifier')
console.log(escapedIdentifier) // '"FooIdentifier"'

pg.escapeLiteral

**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](/apis/client#clientquery) API for more information.

Escapes a string as a SQL literal.

const { escapeLiteral } = require('pg')
const escapedLiteral = escapeLiteral("hello 'world'")
console.log(escapedLiteral) // "'hello ''world'''"