{"id":46824,"library":"x2node-rsparser","title":"x2node-rsparser","description":"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.","status":"active","version":"2.1.15","language":"javascript","source_language":"en","source_url":"https://github.com/boylesoftware/x2node-rsparser","tags":["javascript","sql","x2node","nodejs"],"install":[{"cmd":"npm install x2node-rsparser","lang":"bash","label":"npm"},{"cmd":"yarn add x2node-rsparser","lang":"bash","label":"yarn"},{"cmd":"pnpm add x2node-rsparser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for defining record type libraries that the parser uses to interpret result sets.","package":"x2node-records","optional":false}],"imports":[{"note":"The main class is not directly exported; use getResultSetParser function.","wrong":"const ResultSetParser = require('x2node-rsparser').ResultSetParser;","symbol":"ResultSetParser","correct":"const rsparser = require('x2node-rsparser'); const parser = rsparser.getResultSetParser(recordTypes, 'Person');"},{"note":"This package is CommonJS only; no ESM support. Use require().","wrong":"import { getResultSetParser } from 'x2node-rsparser';","symbol":"getResultSetParser","correct":"const { getResultSetParser } = require('x2node-rsparser');"},{"note":"You must register the rsparser module with x2node-records before building a library that uses result set parsing.","wrong":"","symbol":"records.with(rsparser)","correct":"const records = require('x2node-records'); const rsparser = require('x2node-rsparser'); const recordTypes = records.with(rsparser).buildLibrary({...});"},{"note":"init() expects an array of column name strings, not field objects. Map field objects to their name strings.","wrong":"parser.init(fields);","symbol":"parser.init(fields)","correct":"parser.init(fields.map(field => field.name));"},{"note":"Row can be an array or object; structure must match the column labels defined in init().","wrong":"","symbol":"parser.processRow(row)","correct":"parser.processRow(row);"}],"quickstart":{"code":"const mysql = require('mysql');\nconst records = require('x2node-records');\nconst rsparser = require('x2node-rsparser');\n\n// create record types library\nconst recordTypes = records.with(rsparser).buildLibrary({\n    'Person': {\n        properties: {\n            'id': { valueType: 'number', role: 'id' },\n            'firstName': { valueType: 'string' },\n            'lastName': { valueType: 'string' }\n        }\n    }\n});\n\n// create parser\nconst parser = rsparser.getResultSetParser(recordTypes, 'Person');\n\n// connect to database (example with mysql)\nconst connection = mysql.createConnection({\n    host: 'localhost',\n    user: 'me',\n    password: 'secret',\n    database: 'my_db'\n});\nconnection.connect(err => { if (err) throw err; });\n\n// run a query\nconnection.query(\n    'SELECT id, fname AS firstName, lname AS lastName FROM persons'\n)\n.on('error', err => { throw err; })\n.on('fields', fields => {\n    parser.init(fields.map(field => field.name));\n})\n.on('result', row => {\n    const records = parser.processRow(row);\n    // records is an array of parsed Person objects\n    console.log(JSON.stringify(records));\n})\n.on('end', () => {\n    const allRecords = parser.finish();\n    connection.end();\n});","lang":"javascript","description":"Shows a complete example of using x2node-rsparser with mysql to parse SQL query results into record objects."},"warnings":[{"fix":"Map field objects to their name property: fields.map(f => f.name)","message":"parser.init() must be called before processing rows, and expects column name strings, not field objects.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use const rsparser = require('x2node-rsparser');","message":"CommonJS only; does not support ES modules (import). Attempting to import will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to >=6.10.3, ideally to a modern LTS version.","message":"Node.js engine requirement is >=6.10.3; older versions of Node are no longer supported and may have security issues.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"search_vec":"'-01':25 '-10':26 '2.1.15':23 '2022':24 'array':58 'axe':69 'collect':68 'column':38 'complex':15 'current':20 'data':18 'definit':43 'design':27 'dimension':52 'ecosystem':79 'framework':33 'handl':62 'hierarch':16 'infrequ':72 'javascript':80 'json':17 'label':39 'map':49,60 'modul':6 'multipl':67 'nest':56 'node.js':5 'nodej':83 'object':57,64 'pars':8 'part':29 'polymorph':63 'primarili':73 'record':41,47 'refer':65 'result':11,54 'row':13 'rsparser':3 'select':10 'set':12 'special':36 'sql':9,53,81 'stabl':21 'structur':19,37 'two':51 'two-dimension':50 'type':42 'updat':70 'use':35,75 'version':22 'x2':32,78 'x2node':2,46,82 'x2node-records':45 'x2node-rsparser':1","created_at":"2026-06-07T13:01:48.472217+00:00","updated_at":"2026-06-07T13:01:48.472217+00:00","problems":[{"fix":"Ensure you require('x2node-records') and require('x2node-rsparser'), then call records.with(rsparser).buildLibrary(...)","cause":"Forgetting to import and call records.with(rsparser) before building library.","error":"TypeError: recordTypes.with is not a function"},{"fix":"Use parser.init(fields.map(f => f.name));","cause":"Passing field objects instead of column name strings to parser.init().","error":"Error: init() must be called with an array of strings"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/boylesoftware/x2node-rsparser#readme","github":"https://github.com/boylesoftware/x2node-rsparser","docs":null,"changelog":null,"pypi":null,"npm":"x2node-rsparser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}