Coder Social home page Coder Social logo

gokvlite's Introduction

GoKVLite

gokvlite is a simple key/value store written in go that implements a single file key/value store for use as a library. It is meant to be embedded into another project rather than as a standalone database server. Its inspiration was primarily sqlite (with a near memcache api)

Installation:

> go get github.com/finder/gokvlite

Usage

Sample usage:

package main

import (
        "github.com/finder/gokvlite"
)

func main() {
        //Opens the file, doesn't matter if it exists or not.
        kh, err := gokvlite.Open("/tmp/kvlite.csv")
        if err != nil {
                panic(fmt.Sprintf("Error:", err))
        }

        //Closes the file
        defer kh.Close()

        //Sets a key and checks for errors
        if err = kh.Set("Testing", []byte("This is the data")); err != nil {
                panic(fmt.Sprintf("Error:", err))
        }

        //Gets the key and checks for errors
        data, err := kh.Get("Testing")
        if err != nil {
                panic(fmt.Sprintf("Error:", err))
        }

        //Print out the data
        fmt.Println(string(*data))
}

Exports

Types:

type KeyHandler struct {
    // contains filtered or unexported fields
}
    This struct actually sets/gets/deletes a key from the database

func Open(filename string) (*KeyHandler, error)
    Opens a file to be used as a database. If the file doesn't exist, it'll
    create it and initialize it.

func (kh *KeyHandler) Close() error
    Closes the file returned by Open, can be deferred that way

func (kh *KeyHandler) Del(key string) error
    Deletes the key if it exists. (returns if it doesn't)

func (kh *KeyHandler) Get(key string) (*[]byte, error)
    Gets the data contained at string Returns nil if the key doesn't exist

func (kh *KeyHandler) Set(key string, data []byte) error
    Sets the key to data

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.