What is snowflake-sdk?
The snowflake-sdk npm package is a Node.js driver for connecting to Snowflake, a cloud-based data warehousing service. It allows you to execute SQL queries, manage transactions, and handle various database operations programmatically.
What are snowflake-sdk's main functionalities?
Connecting to Snowflake
This feature allows you to establish a connection to a Snowflake database using the provided account credentials and connection details.
const snowflake = require('snowflake-sdk');
const connection = snowflake.createConnection({
account: 'your_account',
username: 'your_username',
password: 'your_password',
warehouse: 'your_warehouse',
database: 'your_database',
schema: 'your_schema'
});
connection.connect((err, conn) => {
if (err) {
console.error('Unable to connect: ' + err.message);
} else {
console.log('Successfully connected to Snowflake.');
}
});
Executing SQL Queries
This feature allows you to execute SQL queries against the connected Snowflake database and handle the results.
connection.execute({
sqlText: 'SELECT * FROM your_table',
complete: (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);
console.log(rows);
}
}
});
Managing Transactions
This feature allows you to manage transactions by beginning, committing, and rolling back transactions within the Snowflake database.
connection.execute({
sqlText: 'BEGIN TRANSACTION',
complete: (err, stmt, rows) => {
if (err) {
console.error('Failed to begin transaction: ' + err.message);
} else {
console.log('Transaction started.');
// Perform other operations within the transaction
connection.execute({
sqlText: 'COMMIT',
complete: (err, stmt, rows) => {
if (err) {
console.error('Failed to commit transaction: ' + err.message);
} else {
console.log('Transaction committed.');
}
}
});
}
}
});
Other packages similar to snowflake-sdk
pg
The pg package is a PostgreSQL client for Node.js. It provides similar functionalities for connecting to and interacting with PostgreSQL databases, including executing SQL queries and managing transactions. However, it is specific to PostgreSQL and does not support Snowflake.
mysql
The mysql package is a Node.js client for MySQL databases. It offers similar capabilities for connecting to MySQL databases, executing queries, and managing transactions. Like pg, it is specific to MySQL and does not support Snowflake.
mssql
The mssql package is a Microsoft SQL Server client for Node.js. It provides functionalities for connecting to SQL Server databases, executing queries, and managing transactions. It is specific to SQL Server and does not support Snowflake.
NodeJS Driver for Snowflake
.. image:: https://travis-ci.org/snowflakedb/snowflake-connector-nodejs.svg?branch=master
:target: https://travis-ci.org/snowflakedb/snowflake-connector-nodejs
.. image:: https://codecov.io/gh/snowflakedb/snowflake-connector-nodejs/branch/master/graph/badge.svg
:target: https://codecov.io/gh/snowflakedb/snowflake-connector-nodejs
.. image:: https://img.shields.io/npm/v/snowflake-sdk.svg
:target: https://www.npmjs.com/package/snowflake-sdk
.. image:: http://img.shields.io/:license-Apache%202-brightgreen.svg
:target: http://www.apache.org/licenses/LICENSE-2.0.txt
Install
Include :code:snowflake-sdk
in :code:dependencies
section in :code:package.json
:
.. code-block:: json
{
"name": "<your_application_name>",
"version": "<your_application_version>",
"dependencies": {
"...": "...",
"snowflake-sdk": "^1.1.0",
"...": "..."
}
}
And run the :code:npm install
.
Docs
For detailed documentation and basic usage examples, please see the documentation
at NodeJS Driver for Snowflake <https://docs.snowflake.net/manuals/user-guide/nodejs-driver.html>
_
Test
Prepare for Test
Set the Snowflake connection info in parameters.json
and place it in $HOME:
.. code-block:: json
{
"testconnection": {
"SNOWFLAKE_TEST_USER": "<your_user>",
"SNOWFLAKE_TEST_PASSWORD": "<your_password>",
"SNOWFLAKE_TEST_ACCOUNT": "<your_account>",
"SNOWFLAKE_TEST_WAREHOUSE": "<your_warehouse>",
"SNOWFLAKE_TEST_DATABASE": "<your_database>",
"SNOWFLAKE_TEST_SCHEMA": "<your_schema>",
"SNOWFLAKE_TEST_ROLE": "<your_role>"
}
}
Run Tests
.. code-block:: bash
npm test
Package
The npm package can be built by the command:
.. code-block:: bash
npm pack
Note it is not required to build a package to run tests blow.
Development
Reformat Source code
Use WebStorm code style file to format the source code.
.. code-block:: bash
format.sh -mask "*.js" -settings $(pwd)/webstorm-codestyle.xml -R $(pwd)/lib/ -R $(pwd)/test -R $(pwd)/system_test