Execute Query & Return Results

Execute Query and Return Results from Snowflake Statements API

Script snowflake Verified

by rossmccrann ยท 8/17/2022

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 3 days ago
1
//native
2

3
import type { Sql } from "windmill-client@1";
4

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

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

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

30
  return await response.json();
31
}
32

Other submissions
  • Submitted by rossmccrann Deno
    Created 395 days ago
    1
    import type { Sql } from "https://deno.land/x/[email protected]/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