| 1 | import type * as bigquery from "@distilled.cloud/gcp/bigquery_v2"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { RuntimeContext } from "../../RuntimeContext.ts"; |
| 5 | import type { Dataset } from "./Dataset.ts"; |
| 6 | |
| 7 | export interface QueryRequest extends bigquery.QueryRequest {} |
| 8 | |
| 9 | /** |
| 10 | * Runtime binding for BigQuery `jobs.query`. |
| 11 | * |
| 12 | * Bind this operation to a {@link Dataset} in a Function/Action init phase. |
| 13 | * Provide {@link QueryHttp}. Unqualified table names resolve against the |
| 14 | * bound dataset. GoogleSQL is the default (`useLegacySql: false`). |
| 15 | * |
| 16 | * ### Querying |
| 17 | * **Example:** Run a GoogleSQL query |
| 18 | * ```typescript |
| 19 | * const query = yield* GCP.BigQuery.Query(dataset); |
| 20 | * const result = yield* query({ query: "SELECT 1 AS n" }); |
| 21 | * ``` |
| 22 | * |
| 23 | * @binding |
| 24 | * @category BigQuery |
| 25 | */ |
| 26 | export interface Query extends Binding.Service< |
| 27 | Query, |
| 28 | "GCP.BigQuery.Query", |
| 29 | ( |
| 30 | dataset: Dataset, |
| 31 | ) => Effect.Effect< |
| 32 | ( |
| 33 | request: QueryRequest, |
| 34 | ) => Effect.Effect< |
| 35 | bigquery.QueryResponse, |
| 36 | bigquery.QueryJobsError, |
| 37 | RuntimeContext |
| 38 | > |
| 39 | > |
| 40 | > {} |
| 41 | |
| 42 | export const Query = Binding.Service<Query>("GCP.BigQuery.Query"); |