function astToTree(pq) {
const pt = {};
pt.name = "";
pt.name += typeof pq.distinctOpt === "string" ? pq.distinctOpt + " : " : "";
pt.name += pq.type || "";
pt.name +=
typeof pq.value === "string" || typeof pq.value === "number"
? ": " + pq.value
: "";
pt.name += typeof pq === "string" || typeof pq === "number" ? pq : "";
pt.children = [];
[
"from",
"where",
"groupBy",
"orderBy",
"limit",
"partition",
"left",
"right"
].map((a) => {
pq[a] && pt.children.push(astToTree(pq[a]));
});
if (Array.isArray(pq.value)) {
pq.value.map((v) => pt.children.push(astToTree(v)));
} else if (pq.value && !(typeof pq.value === "string")) {
pq.value && pt.children.push(astToTree(pq.value));
}
return pt;
}