Skip to content

Commit

Permalink
Merge pull request #46 from daneshk/main
Browse files Browse the repository at this point in the history
  • Loading branch information
daneshk authored Feb 2, 2024
2 parents a36af8a + b5d3b75 commit b5710b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 93 deletions.
90 changes: 10 additions & 80 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,22 @@
## Overview
This is a Ballerina library for [Snowflake JDBC Driver v3.13.11](https://docs.snowflake.com/en/user-guide/jdbc.html).
The Snowflake JDBC driver is a JDBC type 4 driver that supports the core JDBC functionality in version 1.0 of the JDBC API.
You can create and manage all Snowflake objects, including virtual warehouses, databases, and all database objects.
It also provides the capability to query Snowflake data. You can find reference information for all the Snowflake SQL commands (DDL, DML, and query syntax) [here](https://docs.snowflake.com/en/sql-reference-commands.html). You can find reference information for the system-defined SQL functions [here](https://docs.snowflake.com/en/sql-reference-functions.html).
This Package bundles the latest Snowflake driver so that the Snowflake connector can be used in ballerina projects easily.

## Prerequisites
## Compatibility

Before using this connector in your Ballerina application, complete the following:
| | Version |
|:---|:----------:|
|Snowflake Driver | **3.14.4** |

* Create a [Snowflake](https://www.snowflake.com) account
* Obtain the JDBC driver connection string, username and password by following [this guide](https://docs.snowflake.com/en/user-guide/jdbc-configure.html)

## Quickstart
> The above Snowflake drivers are released under the [The Apache Software License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt).
To use the Snowflake driver library in your Ballerina application, update the .bal file as follows:
## Usage

To add the Snowflake driver dependency the project, simply import the module as below,

### Step 1: Import driver
First, import the following modules into the Ballerina project.
```ballerina
import ballerina/sql;
import ballerinax/java.jdbc;
import ballerinax/snowflake;
import ballerinax/snowflake.driver as _;
```

### Step 2: Create a new connector instance
Provide the JDBC URL, username, password, optional properties and initialize the JDBC client connector with it.
You can find more information [here](https://docs.snowflake.com/en/user-guide/jdbc-configure.html#label-other-jdbc-connection-string-examples).
```ballerina
jdbc:Options options = {
properties: {
warehouse: "<WAREHOUSE>",
db: "<DATABASE>",
schema: "<SCHEMA>"
}
};
string jdbcUrl = "jdbc:snowflake://<ACCOUNT_IDENTIFIER>.snowflakecomputing.com";
string user = "<USERNAMR>";
string password = "<PASSWORD>";
jdbc:Client baseClient = check new (jdbcUrl, user, password, options = options);
```

### Step 3: Invoke connector operation
1. Now you can use the Ballerina JDBC client connector to consume the Snowflake API.

Following is an example on how to verify the version of the driver you are currently using.

Verify your driver version

```ballerina
public function main() {
sql:ParameterizedQuery sqlQuery = `SELECT CURRENT_CLIENT()`;
stream <record {}, sql:Error?> resultStream = baseClient->query(sqlQuery);
record {|record {} value;|}|error? result = resultStream.next();
if result is record {|record {} value;|} {
io:println("Current driver version: ", result.value);
}
}
```
Following is an example on how to verify the warehouse, database, and schema you are currently using.
Verify the warehouse, database, and schema
```ballerina
public function main() {
sql:ParameterizedQuery sqlQuery = `SELECT CURRENT_WAREHOUSE(), CURRENT_DATABASE(), CURRENT_SCHEMA()`;
stream <record {}, sql:Error?> resultStream = baseClient->query(sqlQuery);
record {|record {} value;|}|error? result = resultStream.next();
if result is record {|record {} value;|} {
io:println("Current details: ", result.value);
}
}
```
Following is an example on how to query data from a table called `DEMO`.
Query the data
```ballerina
public function main() {
sql:ParameterizedQuery sqlQuery = `SELECT * FROM DEMO`;
stream <record {}, sql:Error?> resultStream = baseClient->query(sqlQuery);
error? e = resultStream.forEach(isolated function(record {} result) {
io:println("Current query details: ", result);
});
}
```

2. Use `bal run` command to compile and run the Ballerina program.
33 changes: 20 additions & 13 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
Connects to [Snowflake JDBC Driver](https://docs.snowflake.com/en/user-guide/jdbc.html) from Ballerina

## Package overview
The `ballerinax/snowflake.driver` is a [Ballerina](https://ballerina.io/) library for Snowflake JDBC Driver.
This package bundles the latest Snowflake JDBC Driver.
This Package bundles the latest Snowflake driver so that the Snowflake connector can be used in ballerina projects easily.

## Compatibility

| | Version |
|:---|:----------:|
|Snowflake Driver | **3.14.4** |

> The above Snowflake drivers are released under the [The Apache Software License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt).
## Usage

### Compatibility
| | Version |
|-----------------------------------|---------------------------------|
| Ballerina Language | Ballerina Swan Lake 2201.7.0 |
| Snowflake JDBC Driver | 3.13.11 |
To add the Snowflake driver dependency the project, simply import the module as below,

```ballerina
import ballerina/sql;
import ballerinax/snowflake;
import ballerinax/snowflake.driver as _;
```
## Report issues
To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina Extended Library repository](https://github.com/ballerina-platform/ballerina-extended-library)
To report bugs, request new features, start new discussions, etc., go to the [Ballerina Library repository](https://github.com/ballerina-platform/ballerina-library)

## Useful links
- Discuss code changes of the Ballerina project in [ballerina-dev@googlegroups.com](mailto:ballerina-dev@googlegroups.com).
- Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
- Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag
* Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.

0 comments on commit b5710b7

Please sign in to comment.