The Ballerina connector for Snowflake allows you to programmatically access all of the Snowflake applications, databases, APIs, services via the Java Database Connectivity (JDBC) API using Ballerina. It provides operations to execute a wide range of standard DDL Commands, SQL Commands, and SQL Functions for querying data sources. You can find reference information for all the Snowflake SQL commands (DDL, DML, and query syntax) here.
Before using this connector in your Ballerina application, complete the following:
To connect to Snowflake
- Create a Snowflake account.
- Obtain the
passwordwhich you use to login to Snowflake account and
account_identifierwhich uniquely identifies a Snowflake account within your business entity, as well as throughout the global network of Snowflake.
To use the Snowflake connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector and driver
Import the following modules into the Ballerina project:
Step 2: Create a new connector instance
<password> to initialize the Snowflake connector.
Options should be provided as follows, because
requestGeneratedKeys option must be set to
snowflake:NONE as snowflake does not support the retrieval of auto-generated keys.
Depending on your requirement, you can also pass additional optional properties during the client connector initialization. For more information on connection string properties, see Connection String Options.
<account_identifier>is the unique identifies a Snowflake account.
<username>is the username you use to login to Snowflake account.
<password>is the password you use to login to Snowflake account.
You can also define
<password> as configurable strings in your Ballerina program.
Step 3: Invoke the connector operation
Use the Snowflake connector to consume all of the Snowflake applications, databases, APIs, services via the Java Database Connectivity (JDBC) API using Ballerina.
Now let’s take a look at a few sample operations.
COMPANYDBis the database name.
PUBLICis the schema name.
EMPLOYEESis the table name
queryoperation to query data.
Following is a sample code to query data from a table.
executeoperation to perform DML and DDL operations.
Following is a sample code to insert data into a table
batchExecuteoperation to perform a batch of DML and DDL operations.
Following is a sample code to insert multiple records into a table
calloperation to execute a stored procedure.
Following is a sample code to execute the stored procedure named
bal runcommand to compile and run the Ballerina program.