Skip to content

Commit

Permalink
Update the ReadMe file
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Aug 8, 2024
1 parent a87e7ab commit 6e5e613
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
```

Expand Down
26 changes: 18 additions & 8 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
```

Expand Down
1 change: 1 addition & 0 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ public enum LineTerminator {
public enum NilValue {
NULL = "null",
NOT_APPLICABLE = "N/A",
EMPTY_STRING = "",
BAL_NULL = "()"
};

0 comments on commit 6e5e613

Please sign in to comment.