Skip to content

Instantly share code, notes, and snippets.

@dtudury
Created April 21, 2021 18:00
Show Gist options
  • Save dtudury/25e99778a1db241f10da45d5641ec530 to your computer and use it in GitHub Desktop.
Save dtudury/25e99778a1db241f10da45d5641ec530 to your computer and use it in GitHub Desktop.
idea for an sql-like utility for javascript arrays and objects
const a = [
{ m: "a", id: 1 },
{ m: "b", id: 2 },
{ m: "c", id: 3 }
];
const b = [
{ n: "x", id: 1 },
{ n: "y", id: 2 },
{ n: "z", id: 3 }
];
const join = q`
SELECT
a.m AS m,
b.n AS n
FROM
${a} AS a,
${b} AS b
WHERE a.id = b.id
`;
console.log(join);
/*
[
{ m: "a", n: "x" },
{ m: "b", n: "y" },
{ m: "c", n: "z" }
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment