1import * as DynamoDB from "@distilled.cloud/aws/dynamodb";
2import * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Table } from "./Table.ts";
5
6export interface ExecuteTransactionRequest
7 extends DynamoDB.ExecuteTransactionInput {}
8
9export type ExecuteTransactionTables = [Table, ...Table[]];
10
11/**
12 * Runtime binding for `dynamodb:ExecuteTransaction`.
13 *
14 * Bind this operation to one or more tables inside a function runtime to get a
15 * callable that runs a PartiQL transaction. Statements reference the bound
16 * tables by their physical names (resolve them via `table.tableName`); the
17 * host is granted the transactional read/write actions on every bound table.
18 * Provide the `ExecuteTransactionHttp` layer on the Function to satisfy the
19 * binding.
20 * ### PartiQL
21 * **Example:** Run a PartiQL Transaction
22 * ```typescript
23 * const executeTransaction = yield* AWS.DynamoDB.ExecuteTransaction(table);
24 * const tableName = yield* table.tableName;
25 *
26 * yield* executeTransaction({
27 * TransactStatements: [
28 * {
29 * Statement: `UPDATE "${tableName}" SET balance = balance - 10 WHERE pk = ? AND sk = ?`,
30 * Parameters: [{ S: "account#1" }, { S: "balance" }],
31 * },
32 * {
33 * Statement: `UPDATE "${tableName}" SET balance = balance + 10 WHERE pk = ? AND sk = ?`,
34 * Parameters: [{ S: "account#2" }, { S: "balance" }],
35 * },
36 * ],
37 * });
38 * ```
39 *
40 * @binding
41 */
42export interface ExecuteTransaction extends Binding.Service<
43 ExecuteTransaction,
44 "AWS.DynamoDB.ExecuteTransaction",
45 (
46 ...tables: ExecuteTransactionTables
47 ) => Effect.Effect<
48 (
49 request: ExecuteTransactionRequest,
50 ) => Effect.Effect<
51 DynamoDB.ExecuteTransactionOutput,
52 DynamoDB.ExecuteTransactionError
53 >
54 >
55> {}
56
57export const ExecuteTransaction = Binding.Service<ExecuteTransaction>(
58 "AWS.DynamoDB.ExecuteTransaction",
59);