Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ResultSetParser
✓ const rsparser = require('x2node-rsparser'); const parser = rsparser.getResultSetParser(recordTypes, 'Person');
✗ const ResultSetParser = require('x2node-rsparser').ResultSetParser;
The main class is not directly exported; use getResultSetParser function.
getResultSetParser
✓ const { getResultSetParser } = require('x2node-rsparser');
✗ import { getResultSetParser } from 'x2node-rsparser';
This package is CommonJS only; no ESM support. Use require().
records.with(rsparser)
✓ const records = require('x2node-records'); const rsparser = require('x2node-rsparser'); const recordTypes = records.with(rsparser).buildLibrary({...});
You must register the rsparser module with x2node-records before building a library that uses result set parsing.
parser.init(fields)
✓ parser.init(fields.map(field => field.name));
✗ parser.init(fields);
init() expects an array of column name strings, not field objects. Map field objects to their name strings.
parser.processRow(row)
✓ parser.processRow(row);
Row can be an array or object; structure must match the column labels defined in init().
Shows a complete example of using x2node-rsparser with mysql to parse SQL query results into record objects.
const mysql = require('mysql');
const records = require('x2node-records');
const rsparser = require('x2node-rsparser');
// create record types library
const recordTypes = records.with(rsparser).buildLibrary({
'Person': {
properties: {
'id': { valueType: 'number', role: 'id' },
'firstName': { valueType: 'string' },
'lastName': { valueType: 'string' }
}
}
});
// create parser
const parser = rsparser.getResultSetParser(recordTypes, 'Person');
// connect to database (example with mysql)
const connection = mysql.createConnection({
host: 'localhost',
user: 'me',
password: 'secret',
database: 'my_db'
});
connection.connect(err => { if (err) throw err; });
// run a query
connection.query(
'SELECT id, fname AS firstName, lname AS lastName FROM persons'
)
.on('error', err => { throw err; })
.on('fields', fields => {
parser.init(fields.map(field => field.name));
})
.on('result', row => {
const records = parser.processRow(row);
// records is an array of parsed Person objects
console.log(JSON.stringify(records));
})
.on('end', () => {
const allRecords = parser.finish();
connection.end();
});
Errors
Common errors & fixes
TypeError: recordTypes.with is not a function
Forgetting to import and call records.with(rsparser) before building library.
fixEnsure you require('x2node-records') and require('x2node-rsparser'), then call records.with(rsparser).buildLibrary(...) Error: init() must be called with an array of strings
Passing field objects instead of column name strings to parser.init().
fixUse parser.init(fields.map(f => f.name));
Audit
Dependencies
x2node-recordsrequiredRequired for defining record type libraries that the parser uses to interpret result sets.