This repo implements a rudimentary SQLite DB file in Elixir to demonstrate how one might read B-trees in Elixir.
It was built for the "Build Your Own SQLite" Challenge and passes all the stages.
⚠️ This implementation is meant for demo purposes ONLY and is not meant for production use. There are a bunch of shortcuts taken and only a small subset of SQL keywords are supported. TODOs were left in the codebase as a reminder for later refactoring.
There are two databases that you can use:
superheroes.db:- This is a small version of the test database used in the table-scan stage.
- It contains one table:
superheroes. - It is ~1MB in size.
companies.db:- This is a small version of the test database used in the index-scan stage.
- It contains one table:
companies, and one index:idx_companies_country - It is ~7MB in size.
These aren't included in the repository because they're large in size. You can download them by running this script:
./download_sample_databases.shIf the script doesn't work for some reason, you can download the databases directly from codecrafters-io/sample-sqlite-databases.
The following SQL queries are supported:
- You can get the total number of rows in a table (
WHEREclauses are not supported): "SELECT COUNT(*) FROM superheroes" - You can query the
sqlite_schematable: "SELECT tbl_name FROM sqlite_schema" - You must specify the columns to select (
*is not supported): "SELECT id, name FROM companies" - You can only use a single column in the WHERE clause: "SELECT id, name FROM companies WHERE country = 'tonga'"
While CREATE TABLE and CREATE INDEX statements can be parsed by the parser, running those commands won't do anything.
See the lib/lexer.ex moduledocs for more details on supported SQL queries.
You can try the following queries:
./your_program.sh superheroes.db .dbinfo./your_program.sh superheroes.db .tables./your_program.sh companies.db "SELECT id, name FROM companies WHERE country = 'tonga'"You're free to use the code however you'd like (MIT License).