| 1 | import * as rdsdata from "@distilled.cloud/aws/rds-data"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 5 | import type { DBCluster } from "../RDS/DBCluster.ts"; |
| 6 | import type { Secret } from "../SecretsManager/Secret.ts"; |
| 7 | |
| 8 | export interface BatchExecuteStatementOptions { |
| 9 | secret: Secret; |
| 10 | database?: string; |
| 11 | schema?: string; |
| 12 | } |
| 13 | |
| 14 | export interface BatchExecuteStatementRequest extends Omit< |
| 15 | rdsdata.BatchExecuteStatementRequest, |
| 16 | "resourceArn" | "secretArn" | "database" | "schema" |
| 17 | > {} |
| 18 | |
| 19 | /** |
| 20 | * Runtime binding for `rds-data:BatchExecuteStatement` — run one SQL |
| 21 | * statement over many parameter sets in a single Data API call (bulk |
| 22 | * insert/update/delete). |
| 23 | * |
| 24 | * Bind it to a Data-API-enabled `DBCluster` and its credentials secret, |
| 25 | * exactly like `AWS.RDSData.ExecuteStatement`; provide the implementation |
| 26 | * with `Effect.provide(AWS.RDSData.BatchExecuteStatementHttp)`. |
| 27 | * ### Batch Writes |
| 28 | * **Example:** Bulk Insert Rows |
| 29 | * ```typescript |
| 30 | * // init — bind alongside your other Data API operations |
| 31 | * const batchExecuteStatement = yield* AWS.RDSData.BatchExecuteStatement( |
| 32 | * db.cluster, |
| 33 | * { secret: db.secret, database: "app" }, |
| 34 | * ); |
| 35 | * |
| 36 | * // runtime — one statement, one parameter set per row |
| 37 | * const result = yield* batchExecuteStatement({ |
| 38 | * sql: "INSERT INTO todos (id, title) VALUES (:id, :title)", |
| 39 | * parameterSets: rows.map((row) => [ |
| 40 | * { name: "id", value: { longValue: row.id } }, |
| 41 | * { name: "title", value: { stringValue: row.title } }, |
| 42 | * ]), |
| 43 | * }); |
| 44 | * ``` |
| 45 | * |
| 46 | * @binding |
| 47 | */ |
| 48 | export interface BatchExecuteStatement extends Binding.Service< |
| 49 | BatchExecuteStatement, |
| 50 | "AWS.RDSData.BatchExecuteStatement", |
| 51 | ( |
| 52 | cluster: DBCluster, |
| 53 | options: BatchExecuteStatementOptions, |
| 54 | ) => Effect.Effect< |
| 55 | ( |
| 56 | request: BatchExecuteStatementRequest, |
| 57 | ) => Effect.Effect< |
| 58 | rdsdata.BatchExecuteStatementResponse, |
| 59 | rdsdata.BatchExecuteStatementError, |
| 60 | RuntimeContext |
| 61 | > |
| 62 | > |
| 63 | > {} |
| 64 | |
| 65 | export const BatchExecuteStatement = Binding.Service<BatchExecuteStatement>( |
| 66 | "AWS.RDSData.BatchExecuteStatement", |
| 67 | ); |