Skip to content

[WIP] key/document store (BoltDB abstraction) with an API similar to gopkg.in/mgo.v2

License

Notifications You must be signed in to change notification settings

kylewolfe/rumble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rumble GoDoc Build Status Coverage Status

RumbleDB is an abstraction for boltdb that aims to provide a clean API similiar to that of gopkg.in/mgo.v2 without hiding boltdb away from you completely and without locking you in to a specefic encoding.

Why?

The mgo API is awesome, and so is boltdb.

Install

RumbleDB will follow the gopkg.in repository scheme. Rumble is currently unstable.

go get -u gopkg.in/kylewolfe/rumble.v0

RumbleDB Out of the Box

var db *rumble.DB
var err error
   
if db, err = rumble.New("test.db"); err != nil {
	panic(err)
}
       
// structs
bucket := db.Bucket("foo")
for i := 0; i < 3; i++ {
	foo := &struct {
		Id    bson.ObjectId `rumble:"key"`
		Fizz  string
		Count int
	}{
		Fizz:  "buzz",
		Count: i,
	}
	if err = bucket.Put(foo); err != nil {
		panic(err)
	}
	fmt.Printf("newly created id: %s\n", foo.Id.Hex()) // ids generated on the fly like mgo
}

// iteration
i := bucket.NewIter()
foo := &struct {
	Id    bson.ObjectId `rumble:"key"`
	Fizz  string
	Count int
}{}
for i.Next(foo) {
	fmt.Printf("created: %s\n", foo.Id.Time())
}

// maps
bucket = db.Bucket("bar")
m := bson.M{"foo": "bar"}
if err = bucket.Put(m); err != nil {
	panic(err)
}
fmt.Println(m)

// newly created id: 56c4ffb89e56a73ced4227d6
// newly created id: 56c4ffb89e56a73ced4227d7
// newly created id: 56c4ffb89e56a73ced4227d8
// created: 2016-02-17 18:18:16 -0500 EST
// created: 2016-02-17 18:18:16 -0500 EST
// created: 2016-02-17 18:18:16 -0500 EST
// map[_key:[86 196 255 185 158 86 167 60 237 66 39 217] foo:bar]

Bring Your Own Encoding

RumbleDB provides encoding functionality from bson out of the box, but you can use whatever you'd like.

db, _ := rumble.New("my.db")
db.Marshal = json.Marshal
db.Unmarshal = json.Unmarshal

You can also use your own ID format

var i uint32 = 0
db.NewId = func() []byte {
	return []byte(i := atomic.AddUint32(&rowCounter, 1))
}

About

[WIP] key/document store (BoltDB abstraction) with an API similar to gopkg.in/mgo.v2

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages