bolster

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

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

Go to latest
Published: May 27, 2017 License: MIT Imports: 12 Imported by: 0

README

bolster

GoDoc Build Status Coverage Status Go Report Card

Install

go get github.com/nochso/bolster

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound occurs when a specific item could not be found.
	ErrNotFound = errors.New("item not found")
	// ErrBadTransaction occurs when a write-action is aborted early because of a faulty transaction.
	ErrBadTransaction = errors.New("abort early: previous error causes transaction rollback")
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Action txAction

	Err error
	// contains filtered or unexported fields
}

Error combines error with context information.

func (Error) Error

func (e Error) Error() string

Error implements the built-in error interface.

It combines the action, type info and inner error.

func (Error) IsBadTransaction

func (e Error) IsBadTransaction() bool

IsBadTransaction returns true if the inner error is ErrBadTransaction.

func (Error) IsNotFound

func (e Error) IsNotFound() bool

IsNotFound returns true if the inner error is ErrNotFound.

type Store

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

Store can store and retrieve structs.

func Open

func Open(path string, mode os.FileMode, options *bolt.Options) (*Store, error)

Open creates and opens a Store.

func (*Store) Bolt

func (s *Store) Bolt() *bolt.DB

Bolt returns the underlying bolt.DB instance.

func (*Store) Close

func (s *Store) Close() error

Close releases all database resources. All transactions must be closed before closing the database.

func (*Store) Read

func (s *Store) Read(fn func(*Tx) error) error

Read executes a function within the context of a managed read-only transaction. Any error that is returned from the function is returned from the Read() method.

func (*Store) Register

func (s *Store) Register(v ...interface{}) error

Register validates struct types for later use. This will require a write-transaction if the the struct type has never been registered in this store or its definition has been changed since the last call. A struct's type must be registered before it can be used in combination with a Store.

func (*Store) Write

func (s *Store) Write(fn func(*Tx) error) error

Write executes a function within the context of a read-write 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. Any error that is returned from the function or returned from the commit is returned from the Write() method.

type Tx

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

Tx is a read-only or read-write transaction.

func (*Tx) Delete

func (tx *Tx) Delete(v interface{}) error

Delete removes the given item.

If the item does not exist a nil error is returned.

func (*Tx) Get

func (tx *Tx) Get(v interface{}, id interface{}) error

Get fetches an item of v's type by its ID. v must be a pointer to a struct.

func (*Tx) Insert

func (tx *Tx) Insert(v interface{}) error

Insert saves a new item. If an item with the same ID exists an error is returned.

func (*Tx) Truncate

func (tx *Tx) Truncate(v interface{}) error

Truncate deletes all items of v's type.

func (*Tx) Update

func (tx *Tx) Update(v interface{}) error

Update overwrites an existing item.

If the item does not exist an error is returned.

func (*Tx) Upsert

func (tx *Tx) Upsert(v interface{}) error

Upsert either updates or inserts an item.

Directories

Path Synopsis
Package bytesort encodes common types as a binary/byte slices that are bytewise sortable.
Package bytesort encodes common types as a binary/byte slices that are bytewise sortable.
gob

Jump to

Keyboard shortcuts

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