Snowflake: Node.js (snowflake-sdk)
Queries the demo table (load it with the Python example or COPY INTO).
The only change
Section titled “The only change”# host / account URL myorg-myaccount.snowflakecomputing.com warehouse.internal (MachWarehouse Snowflake REST endpoint, HTTPS 443)# account myorg-myaccount the MachWarehouse account name (any label; kept for drivers that require it)# user / password, role, warehouse, database, schema Snowflake values MachWarehouse values (warehouse = compute pool)Here: SNOWFLAKE_ACCESS_URL=https://warehouse.internal.
npm installSNOWFLAKE_ACCOUNT=demo SNOWFLAKE_ACCESS_URL=https://warehouse.internal SNOWFLAKE_USER=app SNOWFLAKE_PASSWORD=... npm startLibrary: snowflake-sdk 3.4.1 (Node.js 20+).
Source
Section titled “Source”The program as it is kept and tested in the Mach Database Warehouse repository; highlighted lines read the connection setting.
// Print revenue per country with snowflake-sdk. Plain Snowflake driver code:// `accessUrl` is the driver's own setting for private links and proxies.import snowflake from 'snowflake-sdk';
const account = process.env.SNOWFLAKE_ACCOUNT;const connection = snowflake.createConnection({ account, accessUrl: process.env.SNOWFLAKE_ACCESS_URL ?? `https://${account}.snowflakecomputing.com`, username: process.env.SNOWFLAKE_USER, password: process.env.SNOWFLAKE_PASSWORD, role: process.env.SNOWFLAKE_ROLE ?? 'ANALYST', warehouse: process.env.SNOWFLAKE_WAREHOUSE ?? 'BI', database: process.env.SNOWFLAKE_DATABASE ?? 'DEMO', schema: process.env.SNOWFLAKE_SCHEMA ?? 'PUBLIC',});
await connection.connectAsync();const rows = await new Promise((resolve, reject) => { connection.execute({ sqlText: 'SELECT country, COUNT(*) AS events, SUM(revenue) AS revenue FROM events GROUP BY country ORDER BY revenue DESC', complete: (err, _stmt, result) => (err ? reject(err) : resolve(result)), });});for (const r of rows) { console.log(`${r.COUNTRY}\t${r.EVENTS}\t${r.REVENUE}`);}connection.destroy(() => {});{ "name": "machwarehouse-example-snowflake-node", "private": true, "type": "module", "scripts": { "start": "node index.mjs" }, "dependencies": { "snowflake-sdk": "3.4.1" }, "engines": { "node": ">=20" }}