| 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 QueryRequest extends TSQ.QueryRequest {} |
| 7 | |
| 8 | /** |
| 9 | * Runtime binding for `timestream-query:Query` — run SQL queries against a |
| 10 | * Timestream {@link Table}. |
| 11 | * |
| 12 | * Bind the operation to a table inside a function runtime to get a callable |
| 13 | * that grants `timestream:Select` on the table (plus the unscoped |
| 14 | * `timestream:DescribeEndpoints` the endpoint-discovery flow needs). The |
| 15 | * query string itself still references the database and table by name. |
| 16 | * |
| 17 | * Provide `Timestream.QueryHttp` on the Function to implement the binding. |
| 18 | * |
| 19 | * ### Querying Data |
| 20 | * **Example:** Count rows in a table |
| 21 | * ```typescript |
| 22 | * // init — bind the operation to the table |
| 23 | * const query = yield* Timestream.Query(table); |
| 24 | * |
| 25 | * // runtime — run a SQL query |
| 26 | * const result = yield* query({ |
| 27 | * QueryString: `SELECT COUNT(*) AS c FROM "${databaseName}"."${tableName}"`, |
| 28 | * }); |
| 29 | * // result.Rows / result.ColumnInfo hold the result set |
| 30 | * ``` |
| 31 | * |
| 32 | * @binding |
| 33 | */ |
| 34 | export interface Query extends Binding.Service< |
| 35 | Query, |
| 36 | "AWS.Timestream.Query", |
| 37 | ( |
| 38 | table: Table, |
| 39 | ) => Effect.Effect< |
| 40 | ( |
| 41 | request: QueryRequest, |
| 42 | ) => Effect.Effect< |
| 43 | TSQ.QueryResponse, |
| 44 | TSQ.QueryError | TSQ.DescribeEndpointsError |
| 45 | > |
| 46 | > |
| 47 | > {} |
| 48 | |
| 49 | export const Query = Binding.Service<Query>("AWS.Timestream.Query"); |