Skip to content

Statements

Source: src/AWS/RedshiftData/Statements.ts

Runtime binding for the Amazon Redshift Data API against a Serverless Workgroup. Exposes the full Data API surface — execute/executeBatch/describe/cancel/getResult/getResultV2, the metadata reads (describeTable, listDatabases, listSchemas, listTables, listStatements) — plus a composite query that submits a statement and polls until it finishes.

At deploy time it grants the workgroup-scoped Data API actions on the workgroup (plus redshift-serverless:GetCredentials for IAM auth) and the statement-scoped actions (DescribeStatement, GetStatementResult, GetStatementResultV2, CancelStatement, ListStatements) which AWS authorizes per statement owner rather than by ARN. The Data API is HTTP-based — no driver, no VPC reach, and no credential plumbing required. Provide the implementation with Effect.provide(AWS.RedshiftData.StatementsHttp).

Query a Workgroup

const sql = yield* RedshiftData.Statements(workgroup, { database: "dev" });
const result = yield* sql.query("SELECT 1 AS n");
// result.Records -> [[{ longValue: 1 }]]

Run a Batch of Statements in One Transaction

const submitted = yield* sql.executeBatch({
Sqls: ["CREATE TABLE IF NOT EXISTS events(id int)", "INSERT INTO events VALUES (1)"],
});
// sub-statement ids are `${submitted.Id}:1`, `${submitted.Id}:2`
const described = yield* sql.describe(submitted.Id!);

Cancel a Running Statement

const submitted = yield* sql.execute({ Sql: "SELECT count(*) FROM big_table" });
const { Status } = yield* sql.cancel(submitted.Id!);

List Databases, Schemas and Tables

const { Databases } = yield* sql.listDatabases();
const { Schemas } = yield* sql.listSchemas({ SchemaPattern: "public" });
const { Tables } = yield* sql.listTables({ SchemaPattern: "public" });
const { ColumnList } = yield* sql.describeTable({ Schema: "public", Table: "events" });

Serve Query Results from a Lambda Function

export default QueryFunction.make(
{ main: import.meta.url, url: true },
Effect.gen(function* () {
const namespace = yield* RedshiftServerless.Namespace("Analytics", {
dbName: "analytics",
adminUsername: "admin",
manageAdminPassword: true,
});
const workgroup = yield* RedshiftServerless.Workgroup("Analytics", {
namespaceName: namespace.namespaceName,
baseCapacity: 8,
});
// init — bind the Data API to the workgroup
const sql = yield* RedshiftData.Statements(workgroup, {
database: "analytics",
});
return {
fetch: Effect.gen(function* () {
// runtime — submit a statement and wait for its rows
const result = yield* sql.query("SELECT count(*) AS n FROM events");
return yield* HttpServerResponse.json({ records: result.Records });
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(RedshiftData.StatementsHttp)),
);