Skip to content

kchasialis/sqlite-rust

Repository files navigation

A minimal SQLite implementation in Rust that parses the SQLite file format and executes basic SQL queries.

Built to learn Rust and understand database internals.

Features

  • File Format Parsing: Reads SQLite database headers, page structures, and B-tree data
  • Query Support:
    • SELECT COUNT(*) FROM <table>
    • SELECT <columns> FROM <table>
    • SELECT <columns> FROM <table> WHERE <column> = '<value>'
  • Index Optimization: Automatically uses B-tree indexes for WHERE clause filtering when available
  • Data Types: Handles INTEGER, TEXT, REAL, and BLOB columns

Running Locally

Requires cargo (1.91) or later.

./your_program.sh sample.db "SELECT id, name FROM apples"

The first run compiles the project and may be slow. Subsequent runs are fast.

Sample Databases

Included:

  • sample.db - Small database with apples and oranges tables (~few KB)

Download separately:

./download_sample_databases.sh
  • superheroes.db - 1MB database for testing table scans
  • companies.db - 7MB database with an index for testing index scans

Explore databases with:

sqlite3 sample.db "SELECT id, name FROM apples"

Implementation Notes

Topics explored:

About

A toy implementation of SQLite in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors