4 ms·
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
by defaultcompany 5y ago
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 https://github.com/weinberg/SQLToy/wiki
Feedback appreciated!
- mrtweetyhack 5y agoWhy would I not just use SQLite or postgres for learning SQL?
- tinfoil_knight 5y agoI made a key value store: https://github.com/tinfoil-knight/tiny-redis 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?
- defaultcompany 5y agoI love this. I actually think making a tiny redis is way more ambitious than a SQL database. It looks like you have a good start! Two articles that really opened my eyes are: A Beginner’s Guide to the True Order of SQL Operations: https://blog.jooq.org/a-beginners-guide-to-the-true-order-of-sql-operations/ https://blog.jooq.org/a-beginners-guide-to-the-true-order-of... Set Theory: the Method To Database Madness: https://medium.com/basecs/set-theory-the-method-to-database-madness-5ec4b4f05d79 https://medium.com/basecs/set-theory-the-method-to-database-...