Key value database. again for learning purposes.
- DB file create
- DB file open
- DB file close
- Create buckets
- Create keys
- Read/Get keys
- Scan keys
- B+tree
- Internal pages
- Leaf pages
- Update keys
- Delete keys
- Free list pages
- Write pages to disk
- Read pages from disk
- Write Free list pages in meta to disk
- Read Free list pages from disk
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))