Skip to content

shxntanu/tinysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinySQL

Writing an SQLite clone from scratch in C. This project was heavily inspired from cstack's amazing guide on writing an SQL Database in C, and aims to build on top of it by extending its functionality to make it as close to SQLite as possble.

This project is unfinished and in active development. Pull requests, suggestions and any sort of help in general is always welcome :)

Architecture

sqlite architecture

sqlite architecture (https://www.sqlite.org/arch.html)

A query goes through a chain of components in order to retrieve or modify data. The front-end consists of the:

  1. tokenizer
  2. parser
  3. code generator

The input to the front-end is a SQL query. the output is sqlite virtual machine bytecode (essentially a compiled program that can operate on the database).

The back-end consists of the:

  1. virtual machine
  2. B-tree
  3. pager
  4. os interface

Installing

  1. macOS: Install CMake using Homebrew
  2. Linux (Ubuntu): Follow this guide. Make sure to download the latest version of CMake.

Try it for yourself

Build

Run make, this will build the binary, then run ./tinysql mydb.db to start.

Test

  • Run all tests at once by running
python -m unittest discover
  • To run a specific test (e.g.):
python -m unittest test.test_insert
  • To run a specific test case (e.g.):
python -m unittest test.test_insert.TestInsert.test_persistence

About

🗂️ SQLite from scratch in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages