Skip to content

fiatjaf/sublevel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sublevel

Separate sections of the same LevelDB. Compatible (at least in the basics -- I didn't test it minuciously) with the nodejs sublevel.

Travis-CI build status API documentation on Godoc.org

package main

import "github.com/fiatjaf/sublevel"

sub := sublevel.MustOpen("example.db").Sub("specific-stuff")

sub.Put([]byte("this"), []byte("2007-04-01"), nil)
dateOfThis := sub.Get([]byte("this"), nil)
sub.Delete([]byte("this"))

Batch operations

db, err := sublevel.Open("example.db")
if err != nil {
    panic(err)
}

// batch on a single sublevel:
sub := db.Sub("some-things")
batch := sub.NewBatch()
batch.Put([]byte("newthing"), []byte("true"))
batch.Delete([]byte("oldthing"))
_ := sub.Write(batch)
// committed.
// ~
// batch on different sublevels:
othersub := db.Sub("other-things")
otherbatch := othersub.NewBatch()
otherbatch.Put([]byte("new-other-thing"), []byte("true"))
otherbatch.Delete([]byte("old-other-thing"))

batchagain := sub.NewBatch()
batchagain.Delete([]byte("newthing"))
batchagain.Put([]byte("newestthing"), []byte("true"))

superbatch := db.MultiBatch(otherbatch, batchagain)
_ := db.Write(superbatch, nil)
// committed.
// ~
// or
b := db.NewBatch()
b.Put("some-things", []byte("newthing"), []byte("true"))
b.Delete("other-things", []byte("old-other-thing"))
b.Put("other-things", []byte("new-other-thing"), []byte("true"))
b.Delete("some-things", []byte("newthing"))
b.Put("some-things", []byte("newestthing"), []byte("true"))
db.Write(b, nil)

sublevel is built on top of goleveldb and supports most methods from there (not all, but in most cases everything you'll need).

About

Separate sections of the same LevelDB.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages