https://github.com/kylewolfe/rumble
[WIP] key/document store (BoltDB abstraction) with an API similar to gopkg.in/mgo.v2
https://github.com/kylewolfe/rumble
boltdb embedded-database mgo
Last synced: 3 months ago
JSON representation
[WIP] key/document store (BoltDB abstraction) with an API similar to gopkg.in/mgo.v2
- Host: GitHub
- URL: https://github.com/kylewolfe/rumble
- Owner: kylewolfe
- License: mit
- Created: 2016-02-17T23:44:00.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-28T15:59:25.000Z (about 9 years ago)
- Last Synced: 2024-06-20T18:36:20.655Z (almost 2 years ago)
- Topics: boltdb, embedded-database, mgo
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
rumble [](http://godoc.org/github.com/kylewolfe/rumble) [](https://travis-ci.org/kylewolfe/rumble) [](https://coveralls.io/r/kylewolfe/rumble)
======
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
```go
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.
```go
db, _ := rumble.New("my.db")
db.Marshal = json.Marshal
db.Unmarshal = json.Unmarshal
```
You can also use your own ID format
```go
var i uint32 = 0
db.NewId = func() []byte {
return []byte(i := atomic.AddUint32(&rowCounter, 1))
}
```