Created
April 21, 2021 18:00
-
-
Save dtudury/25e99778a1db241f10da45d5641ec530 to your computer and use it in GitHub Desktop.
idea for an sql-like utility for javascript arrays and objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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