Skip to main content

Snowflake

Snowflake is the only data platform built for the cloud for all your data and all your users.

TagsDatabaseSaas

Credential configuration

To configure this credential, you need the account, username, password, database and schema to connect to mysql.

Optionally, you can set any of the extra config parameters you can see here.

Here is an example of a filled credential configuration form in YepCode:

Snowflake Snippets available in Editor

note

The title is the triggering text for YepCode to autocomplete the script.

Integration

New integration from credential
const snowflakeClient = yepcode.integration.snowflake('credential-slug')
New integration from plain authentication data
const snowflake = require('snowflake-sdk')

const snowflakeClient = snowflake.createConnection({
account: account,
username: username,
password: password
});

Connect

Establish connection
snowflakeClient.connect(
function(err, conn) {
if (err) {
console.error('Unable to connect: ' + err.message);
} else {
console.log('Successfully connected to Snowflake.');
}
}
);

Execute Statement

Execute statement
const statement = snowflakeClient.execute({
sqlText: "create database testdb",
complete: function (err, stmt, rows) {
if (err) {
console.error(
"Failed to execute statement due to the following error: " + err.message
);
} else {
console.log("Successfully executed statement: " + statement.getSqlText());
}
},
});

Execute Statement with Parameters

Execute statement with binding statement parameters
const statement = snowflakeClient.execute({
sqlText:
"select c1 from (select :1 as c1 union all select :2 as c1) where c1 = :1;",
binds: [1, 2],
complete: function (err, stmt, rows) {
if (err) {
console.error(
"Failed to execute statement due to the following error: " + err.message
);
} else {
console.log("Successfully executed statement: " + statement.getSqlText());
}
},
});

Inline Results

Select returning results inline
snowflakeClient.execute({
sqlText: "select PRODUCT_ID from PRODUCTS",
complete: function (err, stmt, rows) {
if (err) {
console.error(
"Failed to execute statement due to the following error: " + err.message
);
} else {
console.log("Number of rows produced: " + rows.length);
}
rows.forEach((row) => {
console.log("Product id ", row.PRODUCT_ID)
})
},
});

Streaming Results

Select streaming results
const statement = snowflakeClient.execute({
sqlText: "select PRODUCT_ID from PRODUCTS",
});

const stream = statement.streamRows();

stream.on('error', function(err) {
console.error('Unable to consume all rows');
});

stream.on('data', function(row) {
console.log("Product id ", row.PRODUCT_ID)
});

stream.on('end', function() {
console.log('All rows consumed');
});

Destroy Connection

Terminating a connection
snowflakeClient.destroy(function (err, conn) {
if (err) {
console.error("Unable to disconnect: " + err.message);
} else {
console.log("Disconnected connection with id: " + snowflakeClient.getId());
}
});