FaasJS
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security

Documents / @faasjs/pg / getClient

Function: getClient()

getClient(url?): Promise<Client>

Returns a cached client created by createClient.

When url is omitted and the cache contains exactly one client, that client is returned. When the cache is empty, the registered async database bootstrap is awaited to initialize the default client. The built-in bootstrap creates that client from process.env.DATABASE_URL, while callers such as @faasjs/pg-dev can override it for lazy test setup. Throws when no client can be resolved. The bootstrap path is serialized, so concurrent getClient() calls wait on the same bootstrap promise.

Parameters

url?

string

Returns

Promise<Client>

Throws

When the requested URL is not cached.

Throws

When multiple cached clients exist and url is omitted.

Throws

When the registered database bootstrap does not initialize exactly one default client.

Example

import { getClient } from '@faasjs/pg'

const client = await getClient()
const users = await client.query('users')