| 1 | import type * as TSQ from "@distilled.cloud/aws/timestream-query"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export interface PrepareQueryRequest extends TSQ.PrepareQueryRequest {} |
| 7 | |
| 8 | /** |
| 9 | * Runtime binding for `timestream-query:PrepareQuery` — validate a SQL query |
| 10 | * against a Timestream {@link Table} and inspect its result schema and |
| 11 | * parameter mappings without running it. |
| 12 | * |
| 13 | * Bind the operation to the table the SQL reads so the host is granted |
| 14 | * `timestream:PrepareQuery` and `timestream:Select` on it (plus the unscoped |
| 15 | * `timestream:DescribeEndpoints` the endpoint-discovery flow needs). The |
| 16 | * query string itself still references the database and table by name. |
| 17 | * |
| 18 | * Provide `Timestream.PrepareQueryHttp` on the Function to implement the |
| 19 | * binding. |
| 20 | * |
| 21 | * ### Querying Data |
| 22 | * **Example:** Validate a query before running it |
| 23 | * ```typescript |
| 24 | * // init — bind the operation to the table the SQL reads |
| 25 | * const prepareQuery = yield* Timestream.PrepareQuery(table); |
| 26 | * |
| 27 | * // runtime — validate only; Columns/Parameters describe the result shape |
| 28 | * const prepared = yield* prepareQuery({ |
| 29 | * QueryString: `SELECT COUNT(*) AS c FROM "${databaseName}"."${tableName}"`, |
| 30 | * ValidateOnly: true, |
| 31 | * }); |
| 32 | * // prepared.Columns[0].Name === "c" |
| 33 | * ``` |
| 34 | * |
| 35 | * @binding |
| 36 | */ |
| 37 | export interface PrepareQuery extends Binding.Service< |
| 38 | PrepareQuery, |
| 39 | "AWS.Timestream.PrepareQuery", |
| 40 | ( |
| 41 | table: Table, |
| 42 | ) => Effect.Effect< |
| 43 | ( |
| 44 | request: PrepareQueryRequest, |
| 45 | ) => Effect.Effect< |
| 46 | TSQ.PrepareQueryResponse, |
| 47 | TSQ.PrepareQueryError | TSQ.DescribeEndpointsError |
| 48 | > |
| 49 | > |
| 50 | > {} |
| 51 | |
| 52 | export const PrepareQuery = Binding.Service<PrepareQuery>( |
| 53 | "AWS.Timestream.PrepareQuery", |
| 54 | ); |