diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cfe050..b9437c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Build on: push: branches: - - master + - main - 2201.[0-9]+.x repository_dispatch: types: check_connector_for_breaking_changes diff --git a/README.md b/README.md index e1c8bb2..44b42b9 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,18 @@ Now, utilize the available connector operations. #### Read data from the database ```ballerina +// Create the result record to match the columns of the table being queried. +type User record {| + string name; + string email; + string state; +|}; + sql:ParameterizedQuery sqlQuery = `SELECT * FROM Users limit 10`; -stream resultStream = dbClient->query(sqlQuery); -check from record {} result in resultStream +stream resultStream = dbClient->query(sqlQuery); +check from User user in resultStream do { - io:println("Full details of users: ", result); + io:println("Full details of users: ", user); }; ``` @@ -103,6 +110,12 @@ _ = check dbClient->execute(sqlQuery); The `aws.redshift` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/tree/master/examples). +1. [Read data from the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/query) - Connects to AWS Redshift using the Redshift connector and performs a simple SQL query to select all records from a specified table with a limit of 10. + +2. [Insert data in to the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/execute) - Connects to AWS Redshift using the Redshift connector and performs an INSERT operation into a specified table + +3. [Music store](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/music-store) - This example illustrates the process of creating an HTTP RESTful API with Ballerina to perform basic CRUD operations on a database, specifically AWS Redshift, involving setup, configuration, and running examples. + ## Issues and projects The **Issues** and **Projects** tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library [parent repository](https://github.com/ballerina-platform/ballerina-library). diff --git a/ballerina/Module.md b/ballerina/Module.md index 61740bc..57f8e0d 100644 --- a/ballerina/Module.md +++ b/ballerina/Module.md @@ -79,11 +79,18 @@ Now, utilize the available connector operations. #### Read data from the database ```ballerina +// Create the result record to match the columns of the table being queried. +type User record {| + string name; + string email; + string state; +|}; + sql:ParameterizedQuery sqlQuery = `SELECT * FROM Users limit 10`; -stream resultStream = dbClient->query(sqlQuery); -check from record {} result in resultStream +stream resultStream = dbClient->query(sqlQuery); +check from User user in resultStream do { - io:println("Full details of users: ", result); + io:println("Full details of users: ", user); }; ``` @@ -98,3 +105,9 @@ _ = check dbClient->execute(sqlQuery); ## Examples The `aws.redshift` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/tree/master/examples). + +1. [Read data from the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/query) - Connects to AWS Redshift using the Redshift connector and performs a simple SQL query to select all records from a specified table with a limit of 10. + +2. [Insert data in to the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/execute) - Connects to AWS Redshift using the Redshift connector and performs an INSERT operation into a specified table + +3. [Music store](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/music-store) - This example illustrates the process of creating an HTTP RESTful API with Ballerina to perform basic CRUD operations on a database, specifically AWS Redshift, involving setup, configuration, and running examples. diff --git a/ballerina/Package.md b/ballerina/Package.md index 6fab16d..c0e6032 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -80,11 +80,18 @@ Now, utilize the available connector operations. #### Read data from the database ```ballerina +// Create the result record to match the columns of the table being queried. +type User record {| + string name; + string email; + string state; +|}; + sql:ParameterizedQuery sqlQuery = `SELECT * FROM Users limit 10`; -stream resultStream = dbClient->query(sqlQuery); -check from record {} result in resultStream +stream resultStream = dbClient->query(sqlQuery); +check from User user in resultStream do { - io:println("Full details of users: ", result); + io:println("Full details of users: ", user); }; ``` @@ -99,6 +106,12 @@ _ = check dbClient->execute(sqlQuery); The `aws.redshift` connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/tree/master/examples). +1. [Read data from the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/query) - Connects to AWS Redshift using the Redshift connector and performs a simple SQL query to select all records from a specified table with a limit of 10. + +2. [Insert data in to the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/execute) - Connects to AWS Redshift using the Redshift connector and performs an INSERT operation into a specified table + +3. [Music store](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/music-store) - This example illustrates the process of creating an HTTP RESTful API with Ballerina to perform basic operations on a database, specifically AWS Redshift, involving setup, configuration, and running examples. + ## 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-library) diff --git a/examples/README.md b/examples/README.md index 9b00b3d..ac0c745 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,16 +6,18 @@ The `ballerinax/aws.redshift` connector facilitates seamless integration with Am 2. [Insert data in to the database](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/execute) - Connects to AWS Redshift using the Redshift connector and performs an INSERT operation into a specified table +3. [Music store](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/music-store) - This example illustrates the process of creating an HTTP RESTful API with Ballerina to perform basic CRUD operations on a database, specifically AWS Redshift, involving setup, configuration, and running examples. + ## Prerequisites 1. Follow the [instructions](https://github.com/ballerina-platform/module-ballerinax-aws.redshift#set-up-guide) to set up the AWS Redshift cluster. 2. For each example, create a new Ballerina project. Copy the provided example code into the project, and include a `config.toml` file with the necessary JDBC URL, username, and password. Below is an example illustrating how your `config.toml` file should be structured: -```toml - jdbcUrl="" - user="" - password="" -``` + ```toml + jdbcUrl="" + user="" + password="" + ``` ## Running an Example diff --git a/examples/music-store/music_store.md b/examples/music-store/music_store.md index d6635e9..12d9b87 100644 --- a/examples/music-store/music_store.md +++ b/examples/music-store/music_store.md @@ -18,7 +18,7 @@ Configure AWS Redshift API credentials in `Config.toml` within the setup and mus ## Run the Example -1. First, run the [`setup`](setup) ballerina program to set up the `MUSIC_STORE` database used in the sample. Execute the following command: +1. First, run the [`setup`](https://github.com/ballerina-platform/module-ballerinax-aws.redshift/blob/main/examples/music-store/setup) ballerina program to set up the `MUSIC_STORE` database used in the sample. Execute the following command: ```bash cd setup bal run diff --git a/examples/query/query.bal b/examples/query/query.bal index a0a267e..c9b0c1d 100644 --- a/examples/query/query.bal +++ b/examples/query/query.bal @@ -27,11 +27,18 @@ configurable string password = ?; // Initialize the Redshift client redshift:Client dbClient = check new (jdbcUrl, user, password); +// Create the result record to match the columns of the table being queried. +type User record {| + string name; + string email; + string state; +|}; + public function main() returns error? { - sql:ParameterizedQuery sqlQuery = `SELECT * FROM your_table_name limit 10`; - stream resultStream = dbClient->query(sqlQuery); - check from record {} result in resultStream + sql:ParameterizedQuery sqlQuery = `SELECT * FROM Users limit 10`; + stream resultStream = dbClient->query(sqlQuery); + check from User user in resultStream do { - io:println("Full details of users: ", result); + io:println("Full details of users: ", user); }; }