{"id":26940538,"url":"https://github.com/darren277/byodb","last_synced_at":"2026-05-17T00:04:55.274Z","repository":{"id":68703710,"uuid":"542614073","full_name":"darren277/byodb","owner":"darren277","description":"A custom database built in C.","archived":false,"fork":false,"pushed_at":"2022-10-04T10:55:30.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-24T14:51:26.013Z","etag":null,"topics":["database"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darren277.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-28T13:48:30.000Z","updated_at":"2022-10-19T15:34:45.000Z","dependencies_parsed_at":"2023-04-20T22:17:09.573Z","dependency_job_id":null,"html_url":"https://github.com/darren277/byodb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/darren277/byodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darren277%2Fbyodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darren277%2Fbyodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darren277%2Fbyodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darren277%2Fbyodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darren277","download_url":"https://codeload.github.com/darren277/byodb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darren277%2Fbyodb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264605002,"owners_count":23635982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database"],"created_at":"2025-04-02T15:18:56.485Z","updated_at":"2025-10-11T23:12:20.890Z","avatar_url":"https://github.com/darren277.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What is this?\n\nAs a venture into the C programming language, I decided to try out the following tutorial:\n\nhttps://github.com/cstack/db_tutorial\n\nThis is going to be a database built from the ground up.\n\n\n# Notes:\n\nThe creator of the tutorial breaks the abstract architecture (using `sqlite` as an example) of a database down into:\n1. A front end which:\n* Tokenizes input.\n* Parses tokenized input.\n* Generates bytecode from the parsed input for the backend VM.\n2. A back end which:\n* Receives bytecode instructions that operate on a self balancing [B-tree](https://en.wikipedia.org/wiki/B-tree) data structure.\n* A pager for I/O and caching operations.\n\nThe first step in the tutorial is to create a function that accepts user input so that we can provide it with both database queries as well as \"meta-commands\".\n\n_\"Non-SQL statements like .exit are called “meta-commands”. They all start with a dot, so we check for them and handle them in a separate function.\"_\n\n# Feature Branches (From Tutorial)\n\n## First Feature Branch: Adding INSERT and SELECT statements\n\n### Accepting and Interpreting Input\n\nFirst we add our `do_meta_command()` and `prepare_statement()` functions.\n\nWe also create our meta command and statement enums.\n\n### Basic Hardcoded Table\n\nRequirements:\n1. Support `insert` and `select` operations.\n2. Adhere to a simple schema.\n\n_\"SQLite uses a B-tree for fast lookups, inserts and deletes.\"_\n\n\n## Second Feature Branch: Hard Disk Persistence\n\nConverted in memory table data structure to a hard disk memory pager that writes to and reads from a file.\n\n**DEV NOTE**: I started trying to separate functionality from the main c file. I ended up going down a long rabbit hole about the history and use of header files for compiling from multiple file sources. I also encountered some duplicate imports while trying to compile. For now, rather then be bogged down with these constraints I just wrote a simple Python script for merging separate c files into one right before compilation. See `make main` and the `utils.py` file.\n\n\n## Third Feature Branch: Cursor and B-Tree\n\nWe will now need a cursor in order to traverse the rows in our tables.\n\nThe basic insertion functionality for our B-Tree has been implemented.\n\nThe next step will be to add search functionality.\n\n\n## Fourth Feature Branch: Implementing Binary Search for Our B-Tree\n\nAdded `table_find()` function which calls another new function called `leaf_node_find()` to perform a binary search on our B-Tree.\n\nAdded leaf node splitting functionality to create internal nodes. Also added root creation and tracking functions.\n\nSearch functionality was extended by incorporating recursive search of our B-Tree.\n\n\n**NOTE TO SELF**:\nRegarding how we jump from leaf node to leaf node during longer scans:\n_\"To scan the entire table, we need to jump to the second leaf node after we reach the end of the first. To do that, we’re going to save a new field in the leaf node header called “next_leaf”, which will hold the page number of the leaf’s sibling node on the right. The rightmost leaf node will have a next_leaf value of 0 to denote no sibling (page 0 is reserved for the root node of the table anyway).\"_\n\n\n# Next Steps\n\nThere are definitely some ways in which I want to expand on this project:\n1. One is that I need more tests. Maybe I'll implement some coverage checks to make quantify progress along that dimension.\n2. Create some kind of network accessible server for it so that I can build it and run it on remote servers and access it with a URI string.\n3. Add a user system along with password authentication.\n4. Elaborate significantly on the querying languge.\n\n\n# Feature Branches (My Own)\n\n## Multiple Tables (and Databases)\n\nGot not only multiple tables working but also multiple databases.\n\nAdded INTO and FROM clauses to query language.\n\nNote that the current file structure is as follows:\n`{DATABASE_NAME}-{TABLE_NAME}.db`\nEx: `mydb-mytable.db`.\n\nExample:\n```\n./main mydb\n\ndb \u003e insert 1 hello hi INTO mytable\n\ndb \u003e insert 2 hello2 hi2 INTO mytable2\n\ndb \u003e select FROM mytable\n(1, hello, hi)\n\ndb \u003e select FROM mytable2\n(2, hello2, hi2)\n```\n\nFile names:\n`mydb-mytable.db`\n`mydb-mytable2.db`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarren277%2Fbyodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarren277%2Fbyodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarren277%2Fbyodb/lists"}