A simple (read: toy) SQL implementation made from scratch in pure JS.
Basic SELECT from a Demo table.
FROM Test SELECT n,n2,n3
⯈
Basic WHERE clause on a Demo table. SELECT defaults to SELECT *
.
FROM Test WHERE n > 2
⯈
Full CROSS JOIN on Demo tables.
FROM Test, Test
⯈
JOIN with predicate.
FROM Test AS a, Test AS b ON a.n < b.n
⯈
There are even some built-in table valued functions.
FROM RANGE(3,15, 2)
⯈
LOAD is also a table valued function to load data from an arbritrary url.
FROM LOAD('https://api.github.com/users/IJMacD/repos'), Owner
⯈
FROM LOAD('http://www.reddit.com/r/javascript.json'), data.children AS c, c.data AS d
⯈
FROM LOAD('https://dummy.restapiexample.com/api/v1/employees'), data
⯈
You can use expressions in table valued functions.
FROM RANGE(-7,0), LOAD('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=' || DATE(DATE_ADD(CURRENT_DATE(), value, DAY))) AS nasa WHERE media_type = 'image' SELECT nasa.*
⯈
Going deeper...
FROM (FROM LOAD('https://xkcd.com/info.0.json') SELECT num), RANGE(num,num - 10), LOAD('https://xkcd.com/'||value||'/info.0.json')
(won't work in browser due to XKCD CORS issues but works on server)
CTEs are supported.
WITH cte AS (FROM Test_2 WHERE c > 'd') FROM Test, cte ON CHAR(n+97) = c
⯈
As are window functions.
FROM Test SELECT n, n2, RANK() OVER(ORDER BY n2)
⯈
FROM Test SELECT n, SUM(n) OVER(PARTITION BY n2)
⯈
FROM Test SELECT n, SUM(n) OVER(ORDER BY n ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
⯈
Check out the tests for more examples of supported features.