weinberg/SQLToy
weinberg/SQLToy has 274 GitHub stars and 17 forks. Star changes are not measured yet. Last checked 2026-11-14 02:18 UTC. Last push 2025-09-04.
측정된 스타 증가
- in 24h
- 기록 수집 중
- in 7 days
- 기록 수집 중
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
Learn SQL by creating a SQL database in JavaScript
데이터README.md
OriginalWhat is SQLToy?
SQLToy is an in-memory SQL database written in Javascript. It is under 500 lines of code and has zero dependencies. It supports the following SQL operations:
- SELECT
- FROM
- CROSS JOIN
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- WHERE
- GROUP BY
- Aggregate functions: ARRAY_AGG, MAX, MIN, COUNT
- DISTINCT
- ORDER BY
- OFFSET
- LIMIT
- CREATE TABLE
- INSERT INTO
- UPDATE
SQLToy is for learning 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!) gives you a much deeper level of understanding.
A detailed Wiki walks through the code. Please take a look!
To get the most out of this repository you should have familiarity with Javascript and some ES6 syntax. If you are proficient in another programming language like Python or Java you should still be able to figure things out. This is not a primer on how to write a production grade database. No attempts are made at performance optimization or compatibility with any standard. SQLToy does not support persistence, transactions or even parsing queries. There are many ways you can break it. See below for usage.
Read the Wiki
The heart of this repo is not the code itself but the walkthrough which describes what you need to understand it:
This can be found here: SQLToy Wiki
If you are a Javascript programmer I suspect you will find it much simpler than you think. Give it a look!
OK, I will read the Wiki. But how do I use this database?
There are two concepts you should understand in order to use the database. These are described in detail in the wiki section Key Concepts.
SQL order of operations. You must call the operations in the correct order. A "real" database will do this for you. In this database you must call the operations in the correct order yourself.
"Tables in, tables out". All operations in this database (and conceptually in a real database) take tables as input and produce tables as output. So you take a table and provide it to an operation, getting a new table back. To apply multiple operations, supply that new table as an argument to the next operation.
As an example, the following query in both PostgreSQL and SQLToy:
PostgreSQL
SELECT DISTINCT status, club.name, COUNT(*) AS count FROM employee
JOIN employee_club
ON employee_club.a = employee.id
JOIN club
ON club.id = employee_club.b
WHERE employee.salary > 80000
GROUP BY status, club.name
ORDER BY count DESC;
+----------+--------------------+---------+
| status | name | count |
|----------+--------------------+---------|
| active | Cat Lovers | 2 |
| active | Rotary Club | 1 |
| active | BBQ Crew | 1 |
| active | House Builders | 1 |
| inactive | Education for Kids | 1 |
| inactive | Environmentalists | 1 |
+----------+--------------------+---------+
SQLToy
To make this query in SQLToy we must re-order the operations according to the SQL Order of Operations and chain them together:
let employee = FROM('employee');
let employee_club = FROM('employee_club');
result = JOIN(employee, employee_club, (c) => c["employee_club.A"] === c["employee.id"]);
result = JOIN(result, club, (c) => c["employee_club.B"] === c["club.id"] );
result = WHERE(result, (row) => row['employee.salary'] > 150000);
result = GROUP_BY(result, ['employee.status', 'club.name']);
result = COUNT(result, 'club.name');
result = SELECT(result,['employee.status', 'club.name','COUNT(club.name)'],{'COUNT(club.name)': 'count'})
result = DISTINCT(result, ['employee.status', 'club.name', 'count'])
result = ORDER_BY(result, (a,b) => a.count < b.count ? 1 : -1);
table(result);
The resulting table can be viewed with the table() helper and looks like this:
┌─────────────────┬──────────────────────┬───────┐
│ employee.status │ club.name │ count │
├─────────────────┼──────────────────────┼───────┤
│ active │ Cat Lovers │ 2 │
│ active │ Rotary Club │ 1 │
│ active │ BBQ Crew │ 1 │
│ active │ House Builders │ 1 │
│ inactive │ Education for Kids │ 1 │
│ inactive │ Environmentalists │ 1 │
└─────────────────┴──────────────────────┴───────┘
References
A good primer on SQL operation execution order:
https://blog.jooq.org/a-beginners-guide-to-the-true-order-of-sql-operations/
For a good discussion of set theory as it applies to the relational model:
https://medium.com/basecs/set-theory-the-method-to-database-madness-5ec4b4f05d79 .
Contributions
I welcome contributions! The goals of this project are:
- Teach SQL through a simple Javascript SQL database implementation
- Simplicity and readability over features or compatibility with any standard
- As few dependencies as possible
If you have ideas to further these goals you are welcome to submit a pull-request.
License
The code in SQLToy is licensed under The MIT License.
The contents of the Wiki are licensed separately under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,710 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,892 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,490 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,521 스타