https://github.com/shxntanu/tinysql
🗂️ SQLite from scratch in C
https://github.com/shxntanu/tinysql
Last synced: about 1 month ago
JSON representation
🗂️ SQLite from scratch in C
- Host: GitHub
- URL: https://github.com/shxntanu/tinysql
- Owner: shxntanu
- Created: 2024-09-16T16:06:41.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T17:10:29.000Z (7 months ago)
- Last Synced: 2025-02-12T07:23:59.496Z (3 months ago)
- Language: C
- Homepage:
- Size: 282 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tinySQL
Writing an SQLite clone from scratch in C. This project was heavily inspired from [cstack](https://github.com/cstack)'s amazing [guide](https://cstack.github.io/db_tutorial/) 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 (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 generatorThe 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](https://vpsie.com/knowledge-base/how-to-install-cmake-on-ubuntu-20-04/) 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
```bash
python -m unittest discover
```- To run a specific test (e.g.):
```bash
python -m unittest test.test_insert
```- To run a specific test case (e.g.):
```bash
python -m unittest test.test_insert.TestInsert.test_persistence
```