**
SQL Like Syntax In Node for JSON
**
General Capabilities
-
Pass Data
-
Pass JSON File Path
-
SELECT, FROM, WHERE Keywords
-
SUBQUERIES
Basic Query
import { SELECT, FROM, WHERE } from "./node_sql";
const fetch = require("node-fetch");
const data = {
firstName: "Darshan",
lastName: "marathe",
age: 20,
status: {
loggedin: true,
time: new Date(),
from: "web"
}
};
let res = SELECT(["firstName", "lastName", "status.from"], FROM(data));
Query JSON File
let res2 = SELECT(
["name", "models"],
FROM("./data.json"),
WHERE(x => x.models.length > 2));
Query JSON Sub Queries
let item = SELECT(
["models"],
FROM(
SELECT(
["name", "models"],
FROM("./data.json"),
WHERE(x => x.models.length > 2)
))
);
Remote URLS
async function runQuery(){
let res3 = SELECT(["login", "id", "url"], FROM(await fetchData()));
console.log(res3);
}
runQuery();
Group By Clause
//JSON File With GROUP By Clause
let resGroupBy = SELECT(
["*"],
FROM("./data.json"),
null,
GROUPBY((acc, x) => {
x.modelCount = x.models.length
acc.push(x);
return acc;
}, [])
);
console.log("resGroupBy" ,resGroupBy);