JSPM

sql-join-to-json

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q22680F
  • License MIT

Convert 1d sql query results to nested javascript object

Package Exports

  • sql-join-to-json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sql-join-to-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sql-join-to-json

Convert 1d sql query results to nested javascript object

NPM JavaScript Style Guide

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: 'eg@email.com'
    },
    {
        userName: 'Kusi Musah Hussein',
        age: 24,
        street: 'Cari',
        apartment: 'YA11',
        phone: '242532535353',
        email: 'eg2@gmail.com'

    }
];

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: "eg@email.com" },
            { phone: "242532535353", email: "eg2@gmail.com" },
            ],
        },
];

*/

Pull Requests

Pull requests are welcome