| 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 ExecuteSqlOptions { |
| 9 | secret: Secret; |
| 10 | database?: string; |
| 11 | schema?: string; |
| 12 | } |
| 13 | |
| 14 | export interface ExecuteSqlRequest extends Omit< |
| 15 | rdsdata.ExecuteSqlRequest, |
| 16 | "dbClusterOrInstanceArn" | "awsSecretStoreArn" | "database" | "schema" |
| 17 | > {} |
| 18 | |
| 19 | /** |
| 20 | * Runtime binding for the deprecated `rds-data:ExecuteSql` API (Aurora |
| 21 | * Serverless v1 era). Prefer `AWS.RDSData.ExecuteStatement`, which supports |
| 22 | * named parameters and transactions. |
| 23 | * |
| 24 | * Bind it to a Data-API-enabled `DBCluster` and its credentials secret; |
| 25 | * provide the implementation with `Effect.provide(AWS.RDSData.ExecuteSqlHttp)`. |
| 26 | * ### Legacy SQL Execution |
| 27 | * **Example:** Run Raw SQL Statements |
| 28 | * ```typescript |
| 29 | * // init |
| 30 | * const executeSql = yield* AWS.RDSData.ExecuteSql(db.cluster, { |
| 31 | * secret: db.secret, |
| 32 | * database: "app", |
| 33 | * }); |
| 34 | * |
| 35 | * // runtime — statements are passed as a single string, no parameters |
| 36 | * const result = yield* executeSql({ sqlStatements: "SELECT 1" }); |
| 37 | * ``` |
| 38 | * |
| 39 | * @binding |
| 40 | */ |
| 41 | export interface ExecuteSql extends Binding.Service< |
| 42 | ExecuteSql, |
| 43 | "AWS.RDSData.ExecuteSql", |
| 44 | ( |
| 45 | cluster: DBCluster, |
| 46 | options: ExecuteSqlOptions, |
| 47 | ) => Effect.Effect< |
| 48 | ( |
| 49 | request: ExecuteSqlRequest, |
| 50 | ) => Effect.Effect< |
| 51 | rdsdata.ExecuteSqlResponse, |
| 52 | rdsdata.ExecuteSqlError, |
| 53 | RuntimeContext |
| 54 | > |
| 55 | > |
| 56 | > {} |
| 57 | |
| 58 | export const ExecuteSql = Binding.Service<ExecuteSql>("AWS.RDSData.ExecuteSql"); |