sql-join-to-json
v1.0.2
Published
Convert 1d sql query results to nested javascript object
Downloads
10
Readme
sql-join-to-json
Convert 1d sql query results to nested javascript object
Install
npm
$ npm install --save sql-join-to-json
Getting Started
const sqlJoinToJson = require('sql-join-to-json');
const sqlResults = [
{
userName: 'Kusi Musah Hussein',
age: 24,
street: 'Fatih',
apartment: 'CK11',
phone: '24242424242',
email: '[email protected]'
},
{
userName: 'Kusi Musah Hussein',
age: 24,
street: 'Cari',
apartment: 'YA11',
phone: '242532535353',
email: '[email protected]'
}
];
const resultStructure = {
userName: 1,
age: 1,
address: {
street: 1,
apartment: 1
},
contact: {
phone: 1,
email: 1
}
}
const result = sqlJoinToJson(resultStructure, sqlResults)
console.log(result);
/*
Prints
[
{
userName: "Kusi Musah Hussein",
age: 24,
address: [
{ street: "Fatih", apartment: "CK11" },
{ street: "Cari", apartment: "YA11" },
],
contact: [
{ phone: "24242424242", email: "[email protected]" },
{ phone: "242532535353", email: "[email protected]" },
],
},
];
*/
Pull Requests
Pull requests are welcome