From fe7671fcf8c033cd93419840a549cb2dd8ad96d1 Mon Sep 17 00:00:00 2001 From: lahirusamith Date: Tue, 21 Sep 2021 16:52:48 +0530 Subject: [PATCH] Refactor code for suggested changes and remove Dependencies.toml --- .gitignore | 4 + examples/online-shop/Config.toml | 2 +- examples/online-shop/Dependencies.toml | 316 ------------------------- examples/online-shop/README.md | 5 +- examples/online-shop/service.bal | 36 ++- 5 files changed, 31 insertions(+), 332 deletions(-) delete mode 100644 examples/online-shop/Dependencies.toml diff --git a/.gitignore b/.gitignore index d83f4895..41608cd1 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,7 @@ lib/ .project .settings .vscode + +#Examples +examples/**/Dependencies.toml +examples/**/Config.toml diff --git a/examples/online-shop/Config.toml b/examples/online-shop/Config.toml index 23c6ae86..fbf84c2a 100644 --- a/examples/online-shop/Config.toml +++ b/examples/online-shop/Config.toml @@ -2,4 +2,4 @@ USER="balUser" PASSWORD="balpass" HOST="localhost" PORT=1521 -DATABASE="ORCLCDB.localdomain" \ No newline at end of file +DATABASE="ORCLCDB.localdomain" diff --git a/examples/online-shop/Dependencies.toml b/examples/online-shop/Dependencies.toml deleted file mode 100644 index f781c4d1..00000000 --- a/examples/online-shop/Dependencies.toml +++ /dev/null @@ -1,316 +0,0 @@ -# AUTO-GENERATED FILE. DO NOT MODIFY. - -# This file is auto-generated by Ballerina for managing dependency versions. -# It should not be modified by hand. - -[ballerina] -dependencies-toml-version = "2" - -[[package]] -org = "ballerina" -name = "auth" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "regex"} -] - -[[package]] -org = "ballerina" -name = "cache" -version = "3.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "crypto" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "file" -version = "1.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "os"}, - {org = "ballerina", name = "regex"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "http" -version = "2.0.0" -transitive = false -dependencies = [ - {org = "ballerina", name = "auth"}, - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "file"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "jwt"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.decimal"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.runtime"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "lang.value"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "mime"}, - {org = "ballerina", name = "oauth2"}, - {org = "ballerina", name = "observe"}, - {org = "ballerina", name = "regex"}, - {org = "ballerina", name = "time"}, - {org = "ballerina", name = "url"} -] -modules = [ - {org = "ballerina", packageName = "http", moduleName = "http"} -] - -[[package]] -org = "ballerina" -name = "io" -version = "1.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] - -[[package]] -org = "ballerina" -name = "jballerina.java" -version = "0.0.0" -transitive = true - -[[package]] -org = "ballerina" -name = "jwt" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"}, - {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "regex"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.decimal" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.int" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -transitive = true - -[[package]] -org = "ballerina" -name = "lang.runtime" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.value"} -] - -[[package]] -org = "ballerina" -name = "lang.string" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "log" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "observe"} -] - -[[package]] -org = "ballerina" -name = "mime" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.int"} -] - -[[package]] -org = "ballerina" -name = "oauth2" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "cache"}, - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "observe" -version = "0.9.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "os" -version = "1.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "regex" -version = "1.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "sql" -version = "1.0.0" -transitive = false -dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerina", packageName = "sql", moduleName = "sql"} -] - -[[package]] -org = "ballerina" -name = "task" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "time"} -] - -[[package]] -org = "ballerina" -name = "time" -version = "2.0.0" -transitive = false -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "time", moduleName = "time"} -] - -[[package]] -org = "ballerina" -name = "url" -version = "2.0.0" -transitive = true -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerinax" -name = "oracledb" -version = "1.0.0" -transitive = false -dependencies = [ - {org = "ballerina", name = "crypto"}, - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "sql"}, - {org = "ballerina", name = "time"} -] -modules = [ - {org = "ballerinax", packageName = "oracledb", moduleName = "oracledb"} -] - - diff --git a/examples/online-shop/README.md b/examples/online-shop/README.md index d8da44ae..f8bc7f3a 100644 --- a/examples/online-shop/README.md +++ b/examples/online-shop/README.md @@ -1,11 +1,11 @@ # Ballerina OracleDB module Example use case -## overview +## Overview This example demonstrates how to use the ballerina oracledb module to execute, query and call etc. in an oracle database. ## Implementation -These are HTTP RESTful services that are used to insert, create, and retrieve data of a sample database. +These are HTTP RESTful services used to insert, create, and retrieve data of a sample database. ## Prerequisite @@ -44,7 +44,6 @@ These are HTTP RESTful services that are used to insert, create, and retrieve da version = "12.2.0.1" ``` - * *Initial schema, table creation and data insertion* * Start and run the oracle database docker container or standalone database. diff --git a/examples/online-shop/service.bal b/examples/online-shop/service.bal index 17c27943..6ae04b73 100644 --- a/examples/online-shop/service.bal +++ b/examples/online-shop/service.bal @@ -39,11 +39,13 @@ service /onlineshop on new http:Listener(9090) { } resource function get employees/[int id]() returns Employee|error? { - return check dbClient->queryRow(`SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = ${id}`, Employee); + Employee employee = check dbClient->queryRow(`SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = ${id}`); + return employee; } resource function get employees/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM EMPLOYEES`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM EMPLOYEES`); + return count; } resource function get products() returns Product[]|error? { @@ -57,11 +59,13 @@ service /onlineshop on new http:Listener(9090) { } resource function get products/[int id]() returns Product|error? { - return check dbClient->queryRow(`SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ${id}`, Product); + Product product = check dbClient->queryRow(`SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ${id}`); + return product; } resource function get products/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM PRODUCTS`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM PRODUCTS`); + return count; } resource function put products/[int id](@http:Payload Product product) returns string|error? { @@ -84,11 +88,13 @@ service /onlineshop on new http:Listener(9090) { } resource function get customers/[int id]() returns Customer|error? { - return check dbClient->queryRow(`SELECT * FROM CUSTOMERS WHERE CUSTOMER_ID = ${id}`, Customer); + Customer customer = check dbClient->queryRow(`SELECT * FROM CUSTOMERS WHERE CUSTOMER_ID = ${id}`); + return customer; } resource function get customers/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM CUSTOMERS`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM CUSTOMERS`); + return count; } resource function post customers(@http:Payload CustomerInput customer) returns string|error? { @@ -121,11 +127,13 @@ service /onlineshop on new http:Listener(9090) { } resource function get orders/[int id]() returns Order|error? { - return check dbClient->queryRow(`SELECT * FROM ORDERS WHERE ORDER_ID = ${id}`, Order); + Order order = check dbClient->queryRow(`SELECT * FROM ORDERS WHERE ORDER_ID = ${id}`); + return order; } resource function get orders/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM ORDERS`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM ORDERS`); + return count; } resource function get orderitems() returns OrderItem[]|error? { @@ -139,7 +147,8 @@ service /onlineshop on new http:Listener(9090) { } resource function get orderitems/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM ORDER_ITEMS`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM ORDER_ITEMS`); + return count; } resource function get orders/[int id]/items() returns OrderItem[]|error? { @@ -153,7 +162,8 @@ service /onlineshop on new http:Listener(9090) { } resource function get orders/[int id]/items/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM ORDER_ITEMS WHERE ORDER_ID = ${id}`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM ORDER_ITEMS WHERE ORDER_ID = ${id}`); + return count; } resource function get contacts() returns Contact[]|error? { @@ -177,10 +187,12 @@ service /onlineshop on new http:Listener(9090) { } resource function get contacts/[int id]() returns Contact|error? { - return check dbClient->queryRow(`SELECT * FROM CONTACTS WHERE CONTACT_ID = ${id}`, Contact); + Contact contact = check dbClient->queryRow(`SELECT * FROM CONTACTS WHERE CONTACT_ID = ${id}`); + return contact; } resource function get contacts/count() returns int|error? { - return check dbClient->queryRow(`SELECT COUNT(*) FROM CONTACTS`, int); + int count = check dbClient->queryRow(`SELECT COUNT(*) FROM CONTACTS`); + return count; } }