Skip to content
/ cdb Public

Constant Database native golang implementation

License

Notifications You must be signed in to change notification settings

alldroll/cdb

Repository files navigation

CDB golang implementation

Go Report Card GoDoc

cdb is a fast, reliable, simple package for creating and reading constant databases see docs for more details

Advantages

  • Iterator support
  • Thread safe for reading
  • Lazily key, value reading using io.SectionReader
  • Buffered disc write

Example

f, _ := os.Create("test.cdb")
defer f.Close()

handle := cdb.New()

data := []struct {
    key, value string
}{
    {"key1", "value1"},
    {"key2", "value2"},
    {"key3", "value3"},
    {"key4", "value4"},
    {"key5", "value5"},
    {"key6", "value6"},
    {"key7", "value7"},
}

writer, err := handle.GetWriter(f)
if err != nil {
    t.Error(err)
}

for _, c := range data {
    writer.Put([]byte(c.key), []byte(c.value))
}

writer.Close()
reader, _ := handle.GetReader(f)

for _, c := range data {
    value, err := reader.Get([]byte(c.key))
}

Performance tricks

  • File mmap shows better performance. Example.