Skip to main content
The PostgresResourceClient allows you to execute SQL queries against your PostgreSQL database resources.

Usage

import { myPostgresClient } from "./clients";

const result = await myPostgresClient.invoke(
  "SELECT * FROM users WHERE id = $1",
  [123],
  "get-user"
);

if (result.ok) {
  console.log(result.result.rows);
}

Inputs

The invoke method accepts the following arguments:
sql
string
required
The SQL query string to execute. Use $1, $2, etc., for parameterized queries.
params
(string | number | boolean | null)[]
An array of values for the parameterized query.
invocationKey
string
required
A unique identifier for this operation, used for tracing and logging. Must match [a-zA-Z0-9][a-zA-Z0-9._:-]*.
timeoutMs
number
Optional timeout in milliseconds for the query execution.

Outputs

On success (ok: true), the result object contains:
kind
"database"
Discriminator for the response type.
rows
Record<string, unknown>[]
An array of objects representing the rows returned by the query.
rowsAffected
number
The number of rows affected by the query (e.g., for INSERT, UPDATE, DELETE).