kvite

package module
v0.0.0-...-bc62419 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2015 License: Apache-2.0 Imports: 4 Imported by: 2

README

KVite GoDoc Build Status

Overview

KVite is a simple embedded key/value store for Go that uses SQLite for storage.

It is also horribly named. K/V + SQLite => KVite.

Design

The API was influenced heavily by bolt. kvite is safe to use with multiple processes.

Data is stored in a single table per kvite "instance" using a bucket/key/value. Keys are stored as TEXT in the database and referenced as string in Go. Values are stores as BLOB in the database and referenced as []byte in Go.

Interactions with the datastore are done through transactions.

Usage

Typically, one uses the Transaction wrapper. (Error handling omitted for clarity)


import "github.com/mistifyio/kvite"

db, err := kvite.Open("/path/to/my/database.db")

err := db.Transaction(func(tx *Tx) error {
            b, err := tx.CreateBucket("test")

            err = b.Put("foo", []byte("bar"))

            val, err := b.Get("foo")

            err = b.Delete("foo")

            return nil
        })

For full documentation see the godoc

Status

kvite is currently being used in a larger production quality project. The API is not yet stabilized, however.

Documentation

Overview

Package kvite is a simple embedded K/V store backed by SQLite

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

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

Bucket represents a collection of key/value pairs inside the database.

func (*Bucket) Delete

func (b *Bucket) Delete(key string) error

Delete removes a key from the bucket. If the key does not exist then nothing is done and a nil error is returned.

func (*Bucket) ForEach

func (b *Bucket) ForEach(fn func(k string, v []byte) error) error

ForEach executes a function for each key/value pair in a bucket. If the provided function returns an error then the iteration is stopped and the error is returned to the caller.

func (*Bucket) Get

func (b *Bucket) Get(key string) ([]byte, error)

Get retrieves the value for a key in the bucket. Returns a nil value if the key does not exist

func (*Bucket) Put

func (b *Bucket) Put(key string, value []byte) error

Put sets the value for a key in the bucket. If the key exists, then its previous value will be overwritten.

type DB

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

DB is a wrapper around the underlying SQLite database.

func Open

func Open(filename, table string) (*DB, error)

Open opens a KVite datastore. The returned DB is safe for concurrent use by multiple goroutines. It is rarely necessary to close a DB.

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin starts a transaction.

func (*DB) Buckets

func (db *DB) Buckets() ([]string, error)

Buckets returns all the buckets

func (*DB) Close

func (db *DB) Close() error

Close closes the database, releasing any open resources. It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*DB) Transaction

func (db *DB) Transaction(fn func(*Tx) error) error

Transaction executes a function within the context of a managed transaction. If no error is returned from the function then the transaction is committed. If an error is returned then the entire transaction is rolled back. Rollback and Commit cannot be used inside of the function

type Tx

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

Tx wraps most interactions with the datastore.

func (*Tx) Bucket

func (tx *Tx) Bucket(name string) (*Bucket, error)

Bucket gets a bucket by name. Buckets can be created on the fly and do not "exist" until they have keys.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits the transaction.

func (*Tx) CreateBucket

func (tx *Tx) CreateBucket(name string) (*Bucket, error)

CreateBucket is provided for compatibility. It just calls Bucket.

func (*Tx) CreateBucketIfNotExists

func (tx *Tx) CreateBucketIfNotExists(name string) (*Bucket, error)

CreateBucketIfNotExists is provided for compatibility. It just calls Bucket.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback aborts the transaction.

Jump to

Keyboard shortcuts

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