1import type * as sqladmin from "@distilled.cloud/gcp/sqladmin_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { Instance } from "./Instance.ts";
6
7export interface ExecuteSqlRequest extends Omit<
8 sqladmin.ExecuteSqlInstancesRequest,
9 "instance" | "project"
10> {}
11
12/**
13 * Runtime binding for Cloud SQL `instances.executeSql`.
14 *
15 * Bind this operation to an {@link Instance} in a Function/Action init
16 * phase. Provide {@link ExecuteSqlHttp}. The instance must allow the
17 * Execute SQL API (`dataApiAccess: true`).
18 *
19 * Grants `roles/cloudsql.instanceUser` (`cloudsql.instances.executeSql`,
20 * `get`, `login`) on the project under an IAM Condition naming only this
21 * instance.
22 *
23 * ### Executing SQL
24 * **Example:** Run a statement
25 * ```typescript
26 * const executeSql = yield* GCP.SQL.ExecuteSql(db);
27 * const result = yield* executeSql({
28 * body: {
29 * sqlStatement: "SELECT 1",
30 * database: "mysql",
31 * user: "root",
32 * },
33 * });
34 * ```
35 *
36 * @binding
37 * @category SQL
38 */
39export interface ExecuteSql extends Binding.Service<
40 ExecuteSql,
41 "GCP.SQL.ExecuteSql",
42 (
43 instance: Instance,
44 ) => Effect.Effect<
45 (
46 request: ExecuteSqlRequest,
47 ) => Effect.Effect<
48 sqladmin.SqlInstancesExecuteSqlResponse,
49 sqladmin.ExecuteSqlInstancesError,
50 RuntimeContext
51 >
52 >
53> {}
54
55export const ExecuteSql = Binding.Service<ExecuteSql>("GCP.SQL.ExecuteSql");