Skip to content

An in-memory, append-only, single-table clone of SQLite database.

Notifications You must be signed in to change notification settings

harunsasmaz/Light-DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Light-DB

LightDB is an in-memory, append-only, single-table database.

  • In-memory: Database files are located in local device.

  • Append-only: Only insert operation is available, no delete or update.

  • Single-table: There is only a pre-defined table generated in the source code.

LightDB is a tiny clone of SQLite, which uses BTrees for fast lookups and hence insert/delete/update operations.

  • If you are not familiar with Btrees, read this tutorial before starting.

How Does BTree help?

BTree is one type of the balanced trees;

  • It provides O(logn) search cost in the worst case.

  • Insert/delete a cell that is already found is O(1).

  • Re-balancing after an insert is 0(1).

  • Traversing a range of values is fast! (Unlike hashmap)

    • This property allows us to keep rows sorted in database easily.

Our Hard-Coded Table

column type
id integer
username varchar(32)
email varchar(255)
  • Note that this table can be adjusted within the code.

Compile and Run

make

./lightdb {db name}.db

.db extension is not required however .db files can be easily removed by:

make cleandb

Operations

Statements

Insert an element

insert {id} {username} {email}

Print all rows

select

Note that, rows are printed in ascending order by id.

Meta-commands

Exit from DB

.exit

List the BTree

.btree

List constants

.constants

Error Handling

LightDB sends a warning message to the prompt in the following cases:

  • Unrecognized commands.

  • Negative id field.

  • Existing id field. ID is the primary key of the table, so it must be unique.

  • Too long username field.

  • Too long email field.

  • Syntax error.

Next

  • E-mail regex validation.

Acknowledgements

I give special thanks and credit to Connor Stack and his great tutorial here.

About

An in-memory, append-only, single-table clone of SQLite database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published