@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 70 lines 2.17 KB
Raw
1 import * as rdsdata from "@distilled.cloud/aws/rds-data";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import * as Effect from "effect/Effect";
5 import type { DBCluster } from "../RDS/DBCluster.ts";
6 import type { Secret } from "../SecretsManager/Secret.ts";
7
8 export interface BeginTransactionOptions {
9 secret: Secret;
10 database?: string;
11 schema?: string;
12 }
13
14 /**
15 * Runtime binding for `rds-data:BeginTransaction` — open a Data API
16 * transaction and get back a `transactionId` to thread through subsequent
17 * `ExecuteStatement`/`BatchExecuteStatement` calls.
18 *
19 * Bind it to a Data-API-enabled `DBCluster` and its credentials secret;
20 * provide the implementation with
21 * `Effect.provide(AWS.RDSData.BeginTransactionHttp)`. Pair with
22 * `AWS.RDSData.CommitTransaction` / `AWS.RDSData.RollbackTransaction` to
23 * finish the transaction.
24 * ### Transactions
25 * **Example:** Begin, Write, Commit
26 * ```typescript
27 * // init
28 * const beginTransaction = yield* AWS.RDSData.BeginTransaction(db.cluster, {
29 * secret: db.secret,
30 * database: "app",
31 * });
32 * const executeStatement = yield* AWS.RDSData.ExecuteStatement(db.cluster, {
33 * secret: db.secret,
34 * database: "app",
35 * });
36 * const commitTransaction = yield* AWS.RDSData.CommitTransaction(db.cluster, {
37 * secret: db.secret,
38 * });
39 *
40 * // runtime
41 * const tx = yield* beginTransaction();
42 * yield* executeStatement({
43 * sql: "INSERT INTO todos (id, title) VALUES (:id, :title)",
44 * parameters: [
45 * { name: "id", value: { longValue: 1 } },
46 * { name: "title", value: { stringValue: "buy milk" } },
47 * ],
48 * transactionId: tx.transactionId,
49 * });
50 * yield* commitTransaction({ transactionId: tx.transactionId! });
51 * ```
52 *
53 * @binding
54 */
55 export interface BeginTransaction extends Binding.Service<
56 BeginTransaction,
57 "AWS.RDSData.BeginTransaction",
58 (
59 cluster: DBCluster,
60 options: BeginTransactionOptions,
61 ) => Effect.Effect<
62 () => Effect.Effect<
63 rdsdata.BeginTransactionResponse,
64 rdsdata.BeginTransactionError,
65 RuntimeContext
66 >
67 >
68 > {}
69
70 export const BeginTransaction = Binding.Service<BeginTransaction>("AWS.RDSData.BeginTransaction");