1.7.0 • Published 4 years ago

ijmacd-query v1.7.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

JS SQL Query

Build Status

A simple (read: toy) SQL implementation made from scratch in pure JS.

Examples

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.

1.7.0

4 years ago

1.6.9

4 years ago

1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

4 years ago

1.6.5

4 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago