Skip to content

cbluth/mdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mdb

a simple database that can persist to disk or run in ram


to persist to disk:

	db, closeDB, err := mdb.Open(
		&mdb.Config{
			Path: "some/file/path.db",
		},
	)

and example in ram:

package main

import (
	"log"
	"github.com/cbluth/mdb"

)

func main() {
	// open db in ram
	db, closeDB, err := mdb.Open(nil)
	if err != nil {
		log.Fatalln(err)
	}
	defer closeDB()
	
	// set some key-value pairs
	db.SetKV("animal",
		[]mdb.KV{
			{Key: "hungry", Value: "yes"},
			{Key: "hippo", Value: "yes"},
			{Key: "location", Value: "river"},
		},
	)

	// set a map
	m := map[string]string{}
	m["hungry"] = "yes"
	m["hippo"] = "yes"
	m["location"] = "river"
	db.SetMap("animal", m)

	log.Println(
		db.GetKV("animal"),
	)
}

output:

2020/11/12 17:23:32 [{hippo yes} {hungry yes} {location river}] <nil>

TODO:

  • add compression to the db file
  • add auto-sync policy (auto-save to disk)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages