Skip to content

ahmedash95/kvdb

Repository files navigation

KVDB

Key value database. again for learning purposes.

Roadmap

Basic features

  • DB file create
  • DB file open
  • DB file close
  • Create buckets
  • Create keys
  • Read/Get keys
  • Scan keys

Memory B+tree

  • B+tree
  • Internal pages
  • Leaf pages
  • Update keys
  • Delete keys
  • Free list pages

Persistence

  • Write pages to disk
  • Read pages from disk
  • Write Free list pages in meta to disk
  • Read Free list pages from disk

Usage

db, err := Open("test.db", nil)
if err != nil {
    t.Fatal(err)
}

defer db.Close()

bucket := db.Bucket("user_emails")

countryEmails := map[string]string{
    "Zanzibar": "zanzibar@gmail.com",
    "Algeria":  "algeria@gmail.com",
    "Egypt":    "egypt@gmail.com",
}

for country, email := range countryEmails {
    err = bucket.Put([]byte(country), []byte(email))
    if err != nil {
        t.Fatal(err)
    }
}


// Update record
err = bucket.Put([]byte("Egypt"), []byte("cairo@gmail.com")
if err != nil {
    t.Fatal(err)
}

// Fetch record
email, err := bucket.Get([]byte("Egypt"))
if err != nil {
    t.Fatal(err)
}

fmt.Println(string(email))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published