| 1 | import type * as Effect from "effect/Effect"; |
| 2 | import * as Binding from "../../Binding.ts"; |
| 3 | import type { ReadTableClient } from "./ReadTable.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | import type { WriteTableClient } from "./WriteTable.ts"; |
| 6 | |
| 7 | export interface ReadWriteTableClient |
| 8 | extends ReadTableClient, WriteTableClient {} |
| 9 | |
| 10 | /** |
| 11 | * Read and write access to a BigQuery {@link Table}. Grants |
| 12 | * `roles/bigquery.dataEditor` on the table and `roles/bigquery.jobUser` on |
| 13 | * the project (job creation is project-only). |
| 14 | * |
| 15 | * ### Reading and writing |
| 16 | * **Example:** Insert then aggregate |
| 17 | * ```typescript |
| 18 | * const events = yield* GCP.BigQuery.ReadWriteTable(table); |
| 19 | * const tableId = yield* table.tableId; |
| 20 | * return Effect.gen(function* () { |
| 21 | * yield* events.insert([{ id: "a", score: 3 }]); |
| 22 | * const [total] = yield* events.query( |
| 23 | * `SELECT SUM(score) AS total FROM \`${yield* tableId}\``, |
| 24 | * ); |
| 25 | * }); |
| 26 | * // …provided with Effect.provide(GCP.BigQuery.ReadWriteTableHttp) |
| 27 | * ``` |
| 28 | * |
| 29 | * @binding |
| 30 | * @category BigQuery |
| 31 | */ |
| 32 | export interface ReadWriteTable extends Binding.Service< |
| 33 | ReadWriteTable, |
| 34 | "GCP.BigQuery.ReadWriteTable", |
| 35 | (table: Table) => Effect.Effect<ReadWriteTableClient> |
| 36 | > {} |
| 37 | |
| 38 | export const ReadWriteTable = Binding.Service<ReadWriteTable>( |
| 39 | "GCP.BigQuery.ReadWriteTable", |
| 40 | ); |