Class: ReadableCSVChannel
Represents a ReadableCSVChannel which could be used to read records from CSV file.
Constructor
Constructs a CSV channel from a CharacterChannel to read CSV records.
init (ReadableCharacterChannel byteChannel, Separator fs, int nHeaders)
- byteChannel ReadableCharacterChannel
The CharacterChannel, which will represent the content in the CSV file
- fs Separator ","
Field separator, which will separate between the records in the CSV file
- nHeaders int 0
Number of headers, which should be skipped prior to reading records
Methods
skipHeaders | Skips the given number of headers. |
hasNext | Indicates whether there's another record, which could be read. |
getNext | Gets the next record from the CSV file. |
csvStream | Returns a CSV record stream that can be used to CSV records as a stream. |
close | Closes the |
getTable | D Returns a table, which corresponds to the CSV records. |
toTable | Returns a table, which corresponds to the CSV records. |
csvStream
Returns a CSV record stream that can be used to CSV records as a stream.
1stream<string[], io:Error>|io:Error? record = readableCSVChannel.csvStream();
getTable
function getTable(typedesc<record {}> structType, string[ ] fieldNames) returns table<record {}> | Error
Returns a table, which corresponds to the CSV records.
1var tblResult1 = readableCSVChannel.getTable(Employee);2var tblResult2 = readableCSVChannel.getTable(Employee, ["id", "name"]);
Parameters
- structType typedesc<record {}>
The object in which the CSV records should be deserialized
- fieldNames string[ ] (default [])
The names of the fields used as the (composite) key of the table
Return Type
(table<record {}> | Error)Table, which represents the CSV records or else an io:Error
Deprecated
This function is deprecated due to the introduction of ReadableCSVChannel.toTable()
, making 'fieldNames' a mandatory parameter
toTable
function toTable(typedesc<record {}> structType, string[ ] keyFieldNames) returns table<record {}> | Error
Returns a table, which corresponds to the CSV records.
1var tblResult = readableCSVChannel.toTable(Employee, ["id", "name"]);
Parameters
- structType typedesc<record {}>
The object in which the CSV records should be deserialized
- keyFieldNames string[ ]
The names of the fields used as the (composite) key of the table