snowflake-promise

5.0.1 • Public • Published

snowflake-promise npm node

A modern, Promise-based interface for the Snowflake Node.js SDK with full TypeScript support.


Promise Support for the Snowflake SDK

Quick Start

Why use it?

The official Snowflake SDK uses a callback-based API, which can be difficult to manage in modern JavaScript applications. It leads to code that’s hard to understand and hard to maintain.

Promises and async/await are the modern replacement for callbacks. snowflake-promise provides a lightweight adapter that adds Promise support to the SDK's callback-based methods, making it easy to work with Snowflake in Node.js.

Features

  • Works with the official Snowflake Node.js SDK
  • Adds Promise support to callback-based methods
  • Allows you to use async/await for cleaner, more readable code
  • Fully backward compatible with existing (callback-based) code that uses the Snowflake SDK
  • Supports all authentication methods: username/password, MFA, key pair, OAuth
  • Supports all Snowflake SDK features, including streaming large result sets
  • Modern ESM/CJS dual package support
  • Built with 100% test coverage

Basic Usage

snowflake-promise provides a lightweight adapter for the Snowflake Node.js SDK. Pass a Snowflake SDK Connection object to the promisifyConnection function, and it will be enhanced with full Promise support.

Here's a simple example of how to use snowflake-promise to connect to Snowflake, execute a query, and handle the results:

import snowflakeSdk from "snowflake-sdk";
import { promisifyConnection } from "snowflake-promise";

async function main() {
  // Create a connection
  const connection = snowflakeSdk.createConnection({
    account: "<account name>",
    username: "<username>",
    password: "<password>",
    database: "SNOWFLAKE_SAMPLE_DATA",
    schema: "TPCH_SF1",
    warehouse: "DEMO_WH",
  });

  // ✨ Promisify the connection
  const promisifiedConnection = promisifyConnection(connection);

  // Connect (no callbacks -- you can use async/await)
  await promisifiedConnection.connect();

  // Execute a query (no callbacks)
  const { resultsPromise } = promisifiedConnection.execute({
    sqlText: "SELECT COUNT(*) FROM CUSTOMER WHERE C_MKTSEGMENT=:1",
    binds: ["AUTOMOBILE"],
  });

  // Get the results (no callbacks)
  const rows = await resultsPromise;
  console.log(rows);
}

main();

See the Full Documentation for details on:

Package Sidebar

Install

npm i snowflake-promise

Weekly Downloads

32,623

Version

5.0.1

License

MIT

Unpacked Size

94.2 kB

Total Files

9

Last publish

Collaborators

  • natesilva