1
Execute Query & Return Results
One script reply has been approved by the moderators Verified

Execute Query and Return Results from Snowflake Statements API

Created by rossmccrann 858 days ago Viewed 9542 times
0
Submitted by rossmccrann Deno
Verified 858 days ago
1
import type { Sql } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
2

3
export async function main(
4
  token: string,
5
  account_id: string,
6
  database: string,
7
  schema: string,
8
  sql: Sql,
9
) {
10
  const POST_URL = `https://${account_id}.snowflakecomputing.com/api/statements`;
11

12
  const body = {
13
    statement: `${sql}`,
14
    timeout: 60,
15
    database: `${database}`,
16
    schema: `${schema}`,
17
  };
18

19
  const response = await fetch(POST_URL, {
20
    method: "POST",
21
    body: JSON.stringify(body),
22
    headers: {
23
      Authorization: "Bearer " + token,
24
      "Content-Type": "application/json",
25
    },
26
  });
27

28
  return await response.json();
29
}
30