snapshot

package module
v0.0.0-...-97c0035 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2017 License: MIT Imports: 8 Imported by: 0

README

Snapshot

Build Status Project status Go Report Card GoDoc License

Robust, Persistent, Key-Value (KV) store purely written in Golang

Installation
$ go get github.com/thedevsaddam/snapshot
Usage
package main

import (
	"fmt"
	"github.com/thedevsaddam/snapshot"
	"time"
)

//make a type to use
type User struct {
	Name, Occupation string
	CreatedAt        time.Time
}

func main() {

	//create a snapshot collection
	userCollection, err := snapshot.New("users")
	if err != nil {
		fmt.Println(err)
	}

	//add item to collection
	userCollection.Put("john", User{Name: "John Doe", Occupation: "Software Engineer", CreatedAt: time.Now()})
	userCollection.Put("jane", User{Name: "Jane Doe", Occupation: "UI/UX Designer", CreatedAt: time.Now()})

	//get an item from collection
	john := User{}
	userCollection.Get("john", &john)
	fmt.Printf("%s is a %s\n", john.Name, john.Occupation) //John Doe is a Software Engineer

	//check an item is exist in a collection
	fmt.Println(userCollection.Has("john")) //true
	fmt.Println(userCollection.Has("tom"))  //false

	//get all the item keys list
	fmt.Println(userCollection.List())

	//get total item count
	fmt.Println(userCollection.TotalItem())

	//remove a key from collection
	userCollection.Remove("john")

	//remove all the keys with collection
	userCollection.Flush()

}

License

The snapshot is a open-source software licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection describes a collection of key value pairs

func New

func New(name string) (*Collection, error)

New return a instance of collection

func (*Collection) Flush

func (c *Collection) Flush() error

Flush delete a collection with its value

func (*Collection) Get

func (c *Collection) Get(key string, value interface{}) error

Get retrieve a value from collection by key

func (*Collection) Has

func (c *Collection) Has(key string) bool

Has check a key exist in the collection

func (*Collection) List

func (c *Collection) List() ([]string, error)

List fetch all items key in collection

func (*Collection) Put

func (c *Collection) Put(key string, value interface{}) error

Put store a new key with value in the collection

func (*Collection) Remove

func (c *Collection) Remove(key string) error

Remove delete a key from collection

func (*Collection) TotalItem

func (c *Collection) TotalItem() int

TotalItem return total item count

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL