Registry / database / x2node-rsparser

x2node-rsparser

JSON →
library2.1.15jsnpmunverified

A Node.js module for parsing SQL SELECT result set rows into complex hierarchical JSON data structures. Current stable version 2.1.15 (2022-01-10). Designed as part of the X2 Framework, it uses specially structured column labels and record type definitions from x2node-records to map two-dimensional SQL results to nested objects, arrays, and maps. It handles polymorphic objects, references, and multiple collection axes. Updates are infrequent; primarily for use with the X2 ecosystem.

npm install x2node-rsparser
INSTALL
IMPORT
SIG · X2NODE-RSPARSER
X
x2node-rsparser
databasejavascriptv2.1.15
harness data pending
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(); });
Debug
Known issues
gotchaparser.init() must be called before processing rows, and expects column name strings, not field objects.
fix
Map field objects to their name property: fields.map(f => f.name)
affects: >=1.0.0
gotchaCommonJS only; does not support ES modules (import). Attempting to import will fail.
fix
Use const rsparser = require('x2node-rsparser');
affects: >=1.0.0
deprecatedNode.js engine requirement is >=6.10.3; older versions of Node are no longer supported and may have security issues.
fix
Upgrade Node.js to >=6.10.3, ideally to a modern LTS version.
affects: <2.0.0
Errors
Common errors & fixes
TypeError: recordTypes.with is not a function
Forgetting to import and call records.with(rsparser) before building library.
fix
Ensure 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().
fix
Use parser.init(fields.map(f => f.name));
Upgrade
Version history
2.1.15latest on npm
Audit
Dependencies
x2node-recordsrequiredRequired for defining record type libraries that the parser uses to interpret result sets.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
x2node-rsparser — npm install x2node-rsparser · libregistry