/database

Building a clone of the SQLite database from scratch in C

Primary LanguageC

SQLite Clone from stratch in C

  • Author: Anvesh G. Jhuboo
  • Date: 31 Jan 2022
  • Inspired by the work done here

The goal of this exercise is to build a simple database.

  • Set up a REPL
  • Add a simple SQL compiler & Virtual Machine
  • Add In-Memory, Append-Only, Single-Table Database
  • Add Tests (for Bugs)
  • Persistence to Disk
  • The Cursor Abstraction
  • B-Trees
  • B-Tree Leaf Node Format
  • Binary Search and Duplicate Keys
  • Splitting a Leaf Node

Usage so far

~ ./db database.db
db > insert 1 math name@email.com
Executed.
db > insert 2 physics foo@bar.org
Executed.
db > .exit

~ ./db database.db
db > select
(1, math, name@email.com)
(2, physics, foo@bar.com)
Executed.

~ ./db database.db
db > .constants
db > .btree

db > insert foo bar 3
Syntax Error. Could not parse statement.
db > .exit
~

Note

Use vim as a hex editor to view the binary database file in hex format. To do so:

~ vim my_database.db

Inside the binary file opened by vim, do the following command:
:%!xxd