nut

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: MIT Imports: 5 Imported by: 3

README

nutdb

A simple, opinionated wrapper built around boltdb to make common operations easier.

The name is meant to be a simple play on words, because nuts and bolts usually go well together.

Goals

This package aims to keep the simplicity of the bolt interface, but use strings (rather than []byte) for keys and deal with objects by default (rather than []byte).

The entire boltdb interface has not been implemented yet, as I don't personally need all of it. Any unimplemented methods on structs can be found in their respective go files. Any unimplemented types can be found in unimplemented.go If you feel it is missing something, please feel free to open an issue or submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCursorEOF is a marker error signifying that the end of the
	// cursor has been reached.
	ErrCursorEOF = errors.New("End of Cursor")

	// ErrCursorBucket is a marker error signifying that the value is
	// actually a nested bucket.
	ErrCursorBucket = errors.New("Cursor is at bucket")
)

Functions

This section is empty.

Types

type Bucket

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

Bucket is a wrapper around *bolt.Bucket

func (*Bucket) Bucket

func (b *Bucket) Bucket(name string) *Bucket

Bucket is a wrapper around (*bolt.Bucket).Bucket() which takes a string for the bucket name in place of a []byte.

func (*Bucket) CreateBucketIfNotExists

func (b *Bucket) CreateBucketIfNotExists(name string) (*Bucket, error)

CreateBucketIfNotExists is a wrapper around (*bolt.Bucket).CreateBucketIfNotExists which takes a string for the key in place of a []byte.

func (*Bucket) Cursor

func (b *Bucket) Cursor() *Cursor

Cursor is a wrapper around (*bolt.Bucket).Cursor()

func (*Bucket) Delete

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

Delete is a wrapper around (*bolt.Bucket).Delete() which takes a string for the key name in place of a []byte.

func (*Bucket) Get

func (b *Bucket) Get(key string, out interface{}) error

Get is a wrapper around (*bolt.Bucket).Get() which takes a key and a struct to unmarshal into and returns an error if the key does not exist or the Unmarshaling failed.

func (*Bucket) NextID

func (b *Bucket) NextID() (string, error)

NextID is a loose wrapper around (*bolt.Bucket).NextSequence() which will return the next sequence from the DB in base32. This may be changed later, but if this happens, it will be ensured that any new IDs will not conflict with lower IDs.

func (*Bucket) Put

func (b *Bucket) Put(key string, in interface{}) error

Put is a wrapper around (*bolt.Bucket).Put()

Put takes a key and a struct to store and returns an error if the Marshaling or the underlying Put failed.

func (*Bucket) Raw

func (b *Bucket) Raw() *bolt.Bucket

Raw will return a reference to the backing *bolt.Bucket

type Cursor

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

Cursor is a wrapper around *bolt.Cursor

func (*Cursor) Delete

func (c *Cursor) Delete() error

Delete is a wrapper around (*bolt.Cursor).Delete()

func (*Cursor) First

func (c *Cursor) First(out interface{}) (string, error)

First is a wrapper around (*bolt.Cursor).First()

First takes a struct to unmarshal into and returns the key along with any errors that occured.

ErrCursorEOF will be returned if the bucket is empty.

func (*Cursor) Last

func (c *Cursor) Last(out interface{}) (string, error)

Last is a wrapper around (*bolt.Cursor).Last()

Last takes a struct to unmarshal into and returns the key along with any errors that occured.

ErrCursorEOF will be returned if the bucket is empty.

func (*Cursor) Next

func (c *Cursor) Next(out interface{}) (string, error)

Next is a wrapper around (*bolt.Cursor).Next()

Next takes a struct to unmarshal into and returns the key along with any errors that occured.

ErrCursorEOF will be returned if the cursor is at the end of the bucket.

func (*Cursor) Prev

func (c *Cursor) Prev(out interface{}) (string, error)

Prev is a wrapper around (*bolt.Cursor).Prev()

Prev takes a struct to unmarshal into and returns the key along with any errors that occured.

ErrCursorEOF will be returned if the cursor is at the beginning of the bucket.

func (*Cursor) Raw

func (c *Cursor) Raw() *bolt.Cursor

Raw will return a reference to the backing *bolt.Cursor

func (*Cursor) Seek

func (c *Cursor) Seek(key string, out interface{}) (string, error)

Seek is a wrapper around (*bolt.Cursor).Seek()

Prev takes the target key and a struct to unmarshal into and returns the found key along with any errors that occured.

Because this is a wrapper around (*bolt.Cursor).Seek(), if a key does not exist, the next key (and value) will be used.

ErrCursorEOF will be returned if the key does not exist and no keys follow.

type DB

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

DB is a wrapper around *bolt.DB

func NewDB

func NewDB(rawDB *bolt.DB) *DB

NewDB will create a new nutdb given a boltdb.

func Open

func Open(path string, mode os.FileMode) (*DB, error)

Open is a wrapper around bolt.Open which will create a *DB from the resulting *bolt.DB.

NOTE: Options are not currently supported. If you need fancy options set on the underlying *bolt.DB, please use NewDB and pass in the created underlying *bolt.DB yourself.

func (*DB) Close

func (db *DB) Close() error

Close wraps (*bolt.DB).Close()

func (*DB) EnsureBucket

func (db *DB) EnsureBucket(name string) error

EnsureBucket is an addition to the API which will ensure a bucket exists and return an error if it doesn't exist and fails to be created.

func (*DB) Raw

func (db *DB) Raw() *bolt.DB

Raw will return a reference to the backing *bolt.DB

func (*DB) Update

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

Update wraps (*bolt.DB).Update()

func (*DB) View

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

View wraps (*bolt.DB).View()

type Tx

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

Tx is a wrapper around *bolt.Tx

func (*Tx) Bucket

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

Bucket is a wrapper around (*bolt.Tx).Bucket() which takes a string for the key in place of a []byte.

func (*Tx) CreateBucketIfNotExists

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

CreateBucketIfNotExists is a wrapper around (*bolt.Tx).CreateBucketIfNotExists which takes a string for the key in place of a []byte.

func (*Tx) Raw

func (tx *Tx) Raw() *bolt.Tx

Raw will return a reference to the backing *bolt.Tx

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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