Skip to content

Commit

Permalink
Merge pull request #20 from niveathika/main
Browse files Browse the repository at this point in the history
Migrate to SLBeta3
  • Loading branch information
niveathika authored Oct 11, 2021
2 parents a38e3b1 + 8cb0ac2 commit 07733e9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Ballerina Build
uses: ballerina-platform/ballerina-action/@slbeta1
uses: ballerina-platform/ballerina-action/@slbeta3
with:
args:
build -c
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Ballerina Build
uses: ballerina-platform/ballerina-action/@slbeta1
uses: ballerina-platform/ballerina-action/@slbeta3
with:
args:
build -c --skip-tests
Expand All @@ -21,7 +21,7 @@ jobs:
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Ballerina Push
uses: ballerina-platform/ballerina-action/@slbeta1
uses: ballerina-platform/ballerina-action/@slbeta3
with:
args:
push
Expand Down
8 changes: 3 additions & 5 deletions Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
[package]
org="ballerinax"
name="mysql.driver"
version="1.1.1"
version="1.2.0"
authors=["Ballerina"]
keywords=["Azure", "MySQL"]
repository="https://github.com/ballerina-platform/module-ballerinax-mysql.driver"
license=["Apache-2.0"]
distribution = "slbeta3"

[[platform.java11.dependency]]
groupId = "mysql"
artifactId = "mysql-connector-java"
version = "8.0.25"

[build-options]
observabilityIncluded = true
version = "8.0.26"
4 changes: 2 additions & 2 deletions Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This Package bundles the latest MySQL driver so that mysql connector can be used

| | Version |
|:---|:---:|
|Ballerina Language | **Swan Lake Beta 1** |
|MySQL Driver* | **8.0.25** |
|Ballerina Language | **Swan Lake Beta 3** |
|MySQL Driver* | **8.0.26** |

> *MySQL Connector/J 8.0 is released under GPLv2 License.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ This Package bundles the latest MySQL driver so that mysql connector can be used

> **Note:** Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK.

2. Download and install [Ballerina SL Beta 1](https://ballerina.io/).
2. Download and install [Ballerina SL Beta 3](https://ballerina.io/).

## Building the Source

Execute the commands below to build from the source after installing Ballerina Swan Lake Beta 1 version.
Execute the commands below to build from the source after installing Ballerina Swan Lake Beta 3 version.

1. To build the library:
```shell script
Expand Down
44 changes: 3 additions & 41 deletions tests/mysql_query_operation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import ballerina/sql;
import ballerina/test;
import ballerinax/mysql;

// Defines a record to load the query result schema as shown below in the
// 'getDataWithTypedQuery' function. In this example, all columns of the
// customer table will be loaded. Therefore, the `Customer` record will be
// created with all the columns. The column name of the result and the
// defined field name of the record will be matched case insensitively.
type Customer record {|
int customerId;
string lastName;
Expand All @@ -37,80 +32,50 @@ type Customer record {|
// enable it once we add credentials
@test:Config {enable:false}
public function testQueryOperation() returns error? {
// Runs the prerequisite setup for the example.
check beforeExample6();

// Initializes the MySQL client.
mysql:Client mysqlClient = check new (host = host, user = user,
password = password, database = "MYSQL_BBE_1", port = port, options = {serverTimezone: serverTimezone});

// Select the rows in the database table via the query remote operation.
// The result is returned as a stream and the elements of the stream can
// be either a record or an error. The name and type of the attributes
// within the record from the `resultStream` will be automatically
// identified based on the column name and type of the query result.
stream<record{}, error> resultStream =
stream<record{}, error?> resultStream =
mysqlClient->query(`SELECT * FROM Customers`);

// If there is any error during the execution of the SQL query or
// iteration of the result stream, the result stream will terminate and
// return the error.
error? e = resultStream.forEach(function(record {} result) {
io:println("Full Customer details: ", result);
});

// The result of the `count` operation is provided as a record stream.
stream<record{}, error> resultStream2 =
stream<record{}, error?> resultStream2 =
mysqlClient->query(`SELECT COUNT(*) AS total FROM Customers`);

// Since the above `count` query will return only a single row,
// the `next()` operation is sufficient to retrieve the data.
record {|record {} value;|}|error? result = resultStream2.next();
// Checks the result and retrieves the value for the total.
if result is record {|record {} value;|} {
io:println("Total rows in customer table : ", result.value["total"]);
}

// In general cases, the stream will be closed automatically
// when the stream is fully consumed or any error is encountered.
// However, in case if the stream is not fully consumed, the stream
// should be closed specifically.
error? er = resultStream.close();

// The result is returned as a `Customer` record stream and the elements
// of the stream can be either a `Customer` record or an error.
stream<record{}, error> resultStream3 =
stream<Customer, sql:Error?> customerStream =
mysqlClient->query(`SELECT * FROM Customers`, Customer);

// Casts the generic record type to the `Customer` stream type.
stream<Customer, sql:Error> customerStream =
<stream<Customer, sql:Error>>resultStream3;

// Iterates the customer stream.
error? e2 = customerStream.forEach(function(Customer customer) {
io:println("Full Customer details: ", customer);
});

// Performs the cleanup after the example.
check afterExample6(mysqlClient);
}

// Initializes the database as a prerequisite to the example.
function beforeExample6() returns sql:Error? {
mysql:Client mysqlClient = check new (host = host, user = user, password = password, options = {serverTimezone: serverTimezone});

// Creates a database.
sql:ExecutionResult result =
check mysqlClient->execute(`CREATE DATABASE MYSQL_BBE_1`);

// Creates a table in the database.
result = check mysqlClient->execute(`CREATE TABLE MYSQL_BBE_1.Customers
(customerId INTEGER NOT NULL AUTO_INCREMENT, firstName
VARCHAR(300), lastName VARCHAR(300), registrationID INTEGER,
creditLimit DOUBLE, country VARCHAR(300),
PRIMARY KEY (customerId))`);

// Adds the records to the newly-created table.
result = check mysqlClient->execute(`INSERT INTO MYSQL_BBE_1.Customers
(firstName, lastName, registrationID,creditLimit,country) VALUES
('Peter','Stuart', 1, 5000.75, 'USA')`);
Expand All @@ -121,11 +86,8 @@ function beforeExample6() returns sql:Error? {
check mysqlClient.close();
}

// Cleans up the database after running the example.
function afterExample6(mysql:Client mysqlClient) returns sql:Error? {
// Cleans the database.
sql:ExecutionResult result =
check mysqlClient->execute(`DROP DATABASE MYSQL_BBE_1`);
// Closes the MySQL client.
check mysqlClient.close();
}

0 comments on commit 07733e9

Please sign in to comment.