Giter VIP home page Giter VIP logo

nutz's Introduction

nutz Build Status GoDoc Coverage Status

nutz is a library for interacting with bolt databases. It removes the boilerplates and stay faithful with the bolt database view of "simple API".

Where is nutz useful

  • You want to maintain more than one database
  • Your project uses nested buckets extensively.

Installation

go get github.com/gernest/nutz

How to use

package main

import (
	"fmt"

	"github.com/gernest/nutz"
)

func main() {
	databaseName := "my-databse.db"

	// ntz.NewStorage takes the same arguments as *bolt.Open. The differnce is with
	// nutz nothing is opened.
	db := nutz.NewStorage(databaseName, 0600, nil)

	// Creates a new record in the bucket library with key  "lady morgana" and
	// value []byte("A mist of avalon")
	db.Create("library", "lady morgana", []byte("A mist of avalon"))

	// If you want to create a record which will be deep inside buckets. lets say
	// you want to store a record for a teacher. The buckets will be like
	// city>school>class>teacher.
	db.Create("city", "john Doe", []byte("scientist"), "school", "class", "teacher")

	// Retrieving records from a bolt database.
	d := db.Get("library", "lady morgana")

	fmt.Println(string(d.Data) == "A mist of avalon") //=> true

	// lets check if there was any error
	fmt.Println(d.Error) //=> nil

	// Retriving nested buckets .
	n:=db.Get("city","john Doe","school","class","teacher")

	fmt.Println(string(n.Data)=="scientist") //=> true

	// Lets delete the database
	db.DeleteDatabase()

}

Contributing

Start with clicking the star button to make the author and his neighbors happy. Then fork it and submit a pull request for whatever change you want to be added to this project.

Or, open an issue for any questions.

Author

Geofrey Ernest [email protected]

Twitter : @gernesti

License

This project is under the MIT License. See the LICENSE file for the full license text.

nutz's People

Contributors

gernest avatar king-jam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jochasinga

nutz's Issues

Create function replicating behaviour of Update function?

Hi,

To start, I would just like to say that nutz is a great piece of abstraction from boltdb!

However, I just have a small question about the Create function. The following example is modified from the how to use section:

package main

import (
    "fmt"

    "github.com/gernest/nutz"
)

func main() {

    databaseName := "bolt.db"

    db := nutz.NewStorage(databaseName, 0600, nil)

    /* 
    - city
        - school
            - class
                - teacher
                    "john Doe": "scientist"
    */

    db.Create("city", "john Doe", []byte("scientist"), "school", "class", "teacher")

    jDs := db.Get("city", "john Doe", "school", "class", "teacher")

    if jDs.Error != nil {
        fmt.Println(jDs.Error)
    } else {
        fmt.Println("john Doe", string(jDs.Data)) // => john Doe scientist
    }

    /*-----------------------*/ 

    db.Create("city", "john Doe", []byte("mathematician"), "school", "class", "teacher")

    jDm := db.Get("city", "john Doe", "school", "class", "teacher")

    if jDm.Error != nil {
        fmt.Println(jDm.Error)
    } else {
        fmt.Println("john Doe", string(jDm.Data)) // => john Doe scientist
    }

    db.DeleteDatabase()
}

Firstly, a nested bucket is created with the key "john Doe" with the value "scientist". Then a nested bucket is created with the same key but the value "mathematician". You would have expected nutz to return an error because the key already exists and therefore it could not create a new nested bucket. However, the Create function overrides the nested bucket with the key "john Doe" with the value "scientist". Is this behaviour not overlapping with the Update function? If the Create function returned an error when trying to create a bucket with a key that already exists then all that is required to change the value is a simple switch to using the Update function instead. This would more logical and introduce better data consistency in my honest opinion.

Your thoughts / advice will be greatly appreciated.

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.