Class: ResultSetParser

x2node-rsparser~ ResultSetParser

Result set parser.

new ResultSetParser(recordTypes, valueExtractors, topRecordTypeName)

Note: The constructor is not accessible from the client code. Instances are created using module's getResultSetParser() function.
Parameters:
Name Type Description
recordTypes module:x2node-records~RecordTypesLibrary Record types library.
valueExtractors Object.<string, function()> Value extractors.
topRecordTypeName string Name of the record type being parsed.

Members


<readonly> records :Array.<Object>

Array of records extracted from the result set rows. The property is usually read by the client after all result set rows have been fed to the parser.
Type:
  • Array.<Object>

<readonly> recordTypes :module:x2node-records~RecordTypesLibrary

Record types library.
Type:

<readonly> referredRecords :Object.<string, Object>

Records corresponding to references in fetched reference properties. The property is usually read by the client after all result set rows have been fed to the parser.
Type:
  • Object.<string, Object>

Methods


feedRow(row)

Feed a result set row to the parser. Note, the parser must be initialized with markup before rows can be fed to it.
Parameters:
Name Type Description
row Array.<*> | Object.<string, *> The result set row, which can be an array of raw values for each result set column, or an object with column markup as the keys and corresponding raw values as the values.
Throws:
If the row data does not match the markup.
Type
module:x2node-common.X2DataError

init(markup)

Initialize parser with columns markup. A parser instance can be initialized only once. A parser must be initialized before result set rows can be fed to it.
Parameters:
Name Type Description
markup Array.<string> Markup for each column in the result set.
Throws:

merge(parser)

Merge records collected by another parser into this one. The specified other parser must contain the same number of records in the same order. Each record is then merged one by one into the records in this parser.
Parameters:
Name Type Description
parser module:x2node-rsparser~ResultSetParser The other parser.
Throws:
If the specified parser is incompatible with this one.
Type
module:x2node-common.X2UsageError
Returns:
This parser.
Type
module:x2node-rsparser~ResultSetParser

reset()

Reset the parser so that it can be re-used to parse another result set. The method creates new empty records and referredRecords properties and leaves the markup in place, so there is no need to initialize the parser again and the new result set rows can start to be fed to the parser right away.