5 comments

[ 3.5 ms ] story [ 25.8 ms ] thread
I am a Javascript developer and I've used SQL for years but it's always been a bit of a black box. I recently learned about the SQL order of operations and the relational model and it kind of blew my mind. In the process of digesting this information I wrote my own database in Javascript which I think might help others in my same situation. The result is SQLToy.

It is a SQL database written in Javascript. It's under 500 lines of code (including comments) and has zero dependencies.

The purpose of SQLToy is not to use it as a database but to learn SQL. Instead of doing this from the "outside-in" by learning the query language you do it "inside-out" by going through the implementation of the most common SQL operators. Instead of just learning what the operators do, you also learn how they do it which (hopefully!) should lead to a much deeper level of understanding.

A detailed wiki walks through the code of 15 different SQL operations including SELECT, WHERE, JOINs, GROUP BY, Aggregate Functions COUNT, AVG, MAX, MIN to name a few.

The wiki can be found here: https://github.com/weinberg/SQLToy/wiki

Feedback appreciated!

Why would I not just use SQLite or postgres for learning SQL?
I made a key value store: https://github.com/tinfoil-knight/tiny-redis (easy to build compared to a SQL db) and really enjoyed the process.

Making a SQL db is on my list and your wiki seems like a great place to start.

But, I also wanted to know what books/articles/implementations did you refer to create your own?

This is great - love the detail this goes into.