Skip to content

A simple key-value database implementation from scratch in Rust under 300 lines of code.

License

Notifications You must be signed in to change notification settings

alexandreyc/mydb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyDB

A simple key-value database implementation from scratch in Rust under 300 lines of code.

More specifically, it is a reimplemation in Rust of the didactic database CaskDB which is itself inspired by Bitcask.

Features

  • Key/Value data model
  • Embedded (use as a library, no client/server)
  • Disk-based persistence
  • No runtime dependencies

Limitations

  • Keys and values are limited to UTF-8 encoded strings
  • No delete operation
  • No range queries
  • No concurrency controls
  • Memory usage might be high with a lot of keys
  • Startup time might be slow because we need to load all keys from disk to memory

Usage

use mydb::{MyDB, Result};

fn main() -> Result<()> {
    let filename = "data.db";
    let mut db = MyDB::new(filename)?;

    db.set("hello", "world")?;
    assert_eq!(db.get("hello")?, Some("world".to_string()));

    assert_eq!(db.get("nokey")?, None);

    Ok(())
}

Development

Run tests:

cargo test

Build for release:

cargo build --release

License

See LICENSE.

About

A simple key-value database implementation from scratch in Rust under 300 lines of code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages