Code Monkey home page Code Monkey logo

rumble's Introduction

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))
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.