From 6e5e613f29f3d9c48d3883d510e118808b8cdf66 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 05:08:08 +0530 Subject: [PATCH] Update the ReadMe file --- README.md | 26 ++++++++++++++++++-------- ballerina/Package.md | 26 ++++++++++++++++++-------- ballerina/types.bal | 1 + 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 181d189..3381745 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ## Features - **Versatile CSV Data Input**: Accept CSV data as a string, byte array, or a stream and convert it into a subtype of ballerina records or lists. -- **CSV to anydata Value Conversion**: Transform CSV data into expected type which is subtype of ballerina records or lists. -- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina records or lists values through projection. +- **CSV to anydata Value transformation**: Transform CSV data into expected type which is subtype of ballerina record arrays or anydata arrays. +- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina record array or anydata array values through projection. ## Usage ### Converting CSV string to a record array -To convert a CSV string into a record value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. +To convert a CSV string into a record array value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. ```ballerina import ballerina/data.csv; @@ -45,7 +45,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes`, `parseStream`, `parseString`, `parseBytes`and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -74,8 +74,8 @@ Make sure to handle possible errors that may arise during the file reading or CS ## CSV to record array/anydata array of array representation -The CSV Object can be represented as a value of type record/map array or string array of array in Ballerina which facilitates a structured and type-safe approach to handling CSV data. -The conversion of CSV data to subtype of record array or anydata array of array representation is a fundamental feature of the library. +The CSV Object can be represented as a value of type `record/map array` or `string array of array` in Ballerina, which facilitates a structured and type-safe approach to handling CSV data. +The conversion of CSV data to subtype of `record array` or `anydata array of array` representation is a fundamental feature of the library. ```ballerina import ballerina/data.csv; @@ -88,9 +88,19 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + Book[] bookRecords = [{name: "Clean Code", year: 2008}, {name: "Clean Architecture", year: 2017}]; - Book[] author = check csv:parseList(bookArray, customHeaders = ["name", "year"]); - io:println(author); + // Parse and output a record array from a source of string array of arrays. + Book[] books = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books); + + // Parse and output a tuple array from a source of string array of arrays. + [string, int][] books2 = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books2); + + // Transform CSV records to a string array of arrays. + [string, int][] books3 = check csv:transform(bookRecords); + io:println(books3); } ``` diff --git a/ballerina/Package.md b/ballerina/Package.md index 5de4753..ff1deb2 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -5,14 +5,14 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ## Features - **Versatile CSV Data Input**: Accept CSV data as a string, byte array, or a stream and convert it into a subtype of ballerina records or lists. -- **CSV to anydata Value Conversion**: Transform CSV data into expected type which is subtype of ballerina records or lists. -- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina records or lists values through projection. +- **CSV to anydata Value transformation**: Transform CSV data into expected type which is subtype of ballerina record arrays or anydata arrays. +- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina record array or anydata array values through projection. ## Usage ### Converting CSV string to a record array -To convert a CSV string into a record value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. +To convert a CSV string into a record array value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. ```ballerina import ballerina/data.csv; @@ -38,7 +38,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes`, `parseStream`, `parseString`, `parseBytes`and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -67,8 +67,8 @@ Make sure to handle possible errors that may arise during the file reading or CS ## CSV to record array/anydata array of array representation -The CSV Object can be represented as a value of type record/map array or string array of array in Ballerina which facilitates a structured and type-safe approach to handling CSV data. -The conversion of CSV data to subtype of record array or anydata array of array representation is a fundamental feature of the library. +The CSV Object can be represented as a value of type `record/map array` or `string array of array` in Ballerina, which facilitates a structured and type-safe approach to handling CSV data. +The conversion of CSV data to subtype of `record array` or `anydata array of array` representation is a fundamental feature of the library. ```ballerina import ballerina/data.csv; @@ -81,9 +81,19 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + Book[] bookRecords = [{name: "Clean Code", year: 2008}, {name: "Clean Architecture", year: 2017}]; - Book[] author = check csv:parseList(bookArray, customHeaders = ["name", "year"]); - io:println(author); + // Parse and output a record array from a source of string array of arrays. + Book[] books = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books); + + // Parse and output a tuple array from a source of string array of arrays. + [string, int][] books2 = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books2); + + // Transform CSV records to a string array of arrays. + [string, int][] books3 = check csv:transform(bookRecords); + io:println(books3); } ``` diff --git a/ballerina/types.bal b/ballerina/types.bal index 56c0e64..030adb9 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -90,5 +90,6 @@ public enum LineTerminator { public enum NilValue { NULL = "null", NOT_APPLICABLE = "N/A", + EMPTY_STRING = "", BAL_NULL = "()" };