An in-memory SQL database written from scratch in JavaScript — a hand-written
SQL parser and storage engine with zero dependencies. You give it SQL strings;
it creates databases and tables, stores rows, and answers SELECT queries.
A learning project: the goal was to understand how a SQL engine parses and executes statements by building one, not to be a production database. See Limitations.
npm install sql-nodejsZero dependencies; requires Node 18 or newer. To pin a specific release:
npm install sql-nodejs@0.0.6To work on the project itself:
git clone https://github.com/Megapixel99/sql-nodejs.gitconst SqlParser = require('sql-nodejs');
const db = new SqlParser();
// Logging is off by default; pass `true` to log database switches:
// const db = new SqlParser(true);
db.Parse('CREATE DATABASE mydb;');
db.Parse('CREATE TABLE users (id INT, name VARCHAR, age INT);');
db.Parse('INSERT INTO users (id, name, age) VALUES (1, alice, 30);');
db.Parse('INSERT INTO users (id, name, age) VALUES (2, bob, 25);');
db.Parse('SELECT * FROM users;');
// → [ ['1', 'alice', '30'], ['2', 'bob', '25'] ]
db.Parse('SELECT name, age FROM users;');
// → [ ['alice', '30'], ['bob', '25'] ]
db.Parse('SELECT * FROM users WHERE age=25;');
// → [ ['2', 'bob', '25'] ]SELECT returns an array of rows, where each row is an array of the requested
column values in the order you asked for them.
| Statement | Notes | ||||||||
|---|---|---|---|---|---|---|---|---|---|
CREATE DATABASE <name> |
also becomes the active database | ||||||||
USE <name> |
switch the active database | ||||||||
CREATE TABLE <name> (<col> <type>, …) |
|||||||||
INSERT INTO <table> (<cols>) VALUES (<values>) |
one row per statement | ||||||||
| `SELECT <cols | *> FROM [WHERE =]`
npm testThat runs
To run a single file: node --test test/sql.test.jsTo re-run the suite as you edit: node --test --watchEvery push and pull request runs the same suite on Node 18, 20, 22, and 24 via
GitHub Actions ( This is a deliberately small learning project:
MIT © Seth Wheeler |