store

package
v0.0.0-...-0eeec4f Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2015 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

wrapper for Bolt database

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("Item not found")
View Source
var Never = time.Time{}

time value to check for "unset" metadata time

Functions

This section is empty.

Types

type BasicKey

type BasicKey struct {
	KeyData []byte
}

Use this to wrap items that do not generate a key from their own data. Note that upon creating new items, you must call SetKey() to set up the key value.

func (*BasicKey) Key

func (b *BasicKey) Key() []byte

return key

func (*BasicKey) SetKey

func (b *BasicKey) SetKey(key []byte)

set key

type Byte

type Byte struct {
	BasicKey
	Data []byte
}

Use this to wrap pure binary data items. These will have to embed this struct and define their own methods StoreID and Key.

func (*Byte) Bytes

func (b *Byte) Bytes() ([]byte, error)

return data content

func (*Byte) DeserializeFrom

func (b *Byte) DeserializeFrom(d []byte) error

passthrough deserialization

func (*Byte) Get

func (b *Byte) Get() []byte

get contained data

func (*Byte) Set

func (b *Byte) Set(d []byte)

set contained data

type ContainedKey

type ContainedKey struct{}

A no-op wrapper for items that generate/contain their own key

func (*ContainedKey) SetKey

func (c *ContainedKey) SetKey(key []byte)

no operation for the SetKey method

type DB

type DB struct {
	NotifyQuit *topic.Topic

	*bolt.DB
	// contains filtered or unexported fields
}

Wrapper for a single Bolt database

func Open

func Open(file string) (b *DB, err error)

open a bolt database file

func (*DB) Batch

func (b *DB) Batch(f func(tx *bolt.Tx) error) error

wrapper that can be used for debugging purposes

func (*DB) Close

func (b *DB) Close()

Shut down database, end all registered tasks.

func (*DB) Delete

func (b *DB) Delete(tx *bolt.Tx, item Item) error

delete an item

func (*DB) EnableTransactionDebug

func (b *DB) EnableTransactionDebug()

enable a debugger for bolt database transactions

func (*DB) Exists

func (b *DB) Exists(tx *bolt.Tx, key []byte, item Item) bool

test for the existence of an item, identified by key The item parameter must be a pointer to an item of the kind to be tested for.

func (*DB) ForEach

func (b *DB) ForEach(tx *bolt.Tx, item Item, handler func(cursor *bolt.Cursor) (bool, error)) error

iterate through the items in a bucket Calls a callback function handler, which will get the key and the cursor as parameters so it can do deleten. The actual item is stored to the item parameter - must be a pointer. When the callback handler returns true, that will trigger a reset of the loop, starting anew. Do this after a delete.

func (*DB) ForEachReverse

func (b *DB) ForEachReverse(tx *bolt.Tx, item Item, handler func(cursor *bolt.Cursor) (bool, error)) error

like ForEach, but running from last item to first one

func (*DB) Get

func (b *DB) Get(tx *bolt.Tx, key []byte, item Item) error

get an item, identified by key. The item parameter must be a pointer to the value that will get set.

func (*DB) Purger

func (b *DB) Purger(itemtype Item, interval time.Duration, notifyQuit, notifyPurge *topic.Topic)

Run a background task to purge invalid items of a given type in given intervals. Pass a *topic.Topic to be able to receive NotifyPurge messages for each purged item.

func (*DB) Put

func (b *DB) Put(tx *bolt.Tx, item Item) error

put an item to the corresponding store

func (*DB) Update

func (b *DB) Update(f func(tx *bolt.Tx) error) error

wrapper that can be used for debugging purposes

func (*DB) UpdateMeta

func (b *DB) UpdateMeta(tx *bolt.Tx, olditem *Meta, newitem *Meta) error

update a record that is encapsuled in a Meta struct

func (*DB) View

func (b *DB) View(f func(tx *bolt.Tx) error) error

wrapper that can be used for debugging purposes

type Flag

type Flag struct{ BasicKey }

You can use this to implement simple Flag items. These will have to embed this struct and define their own method StoreID.

func (*Flag) Bytes

func (f *Flag) Bytes() ([]byte, error)

return empty []byte as encoded data

func (*Flag) DeserializeFrom

func (f *Flag) DeserializeFrom(d []byte) error

no-op deserialization

type Item

type Item interface {
	// return a key for the data item
	Key() []byte
	// return a store id for the data item
	StoreID() []byte
	// serialize data item
	Bytes() ([]byte, error)
	// unserialize data item
	DeserializeFrom([]byte) error
	// set key when reading
	SetKey([]byte)
}

For convenient storage, special methods are provided that apply to data which fulfills the Item interface

type Meta

type Meta struct {
	// first creation of an item with this key in this store
	Created time.Time
	// last update of the item with this key in this store
	Updated time.Time
	// date when this item becomes invalid and may be purged
	Invalid time.Time
	// contains filtered or unexported fields
}

Database entry metadata

func NewMeta

func NewMeta(item Item) *Meta

Create a new Meta element

func (*Meta) Bytes

func (m *Meta) Bytes() ([]byte, error)

fast Meta binary encoder

func (*Meta) DeserializeFrom

func (m *Meta) DeserializeFrom(d []byte) error

fast Meta binary decoder

func (*Meta) GetItem

func (m *Meta) GetItem(item Item) error

Access contained item

func (*Meta) GetTransfer

func (m *Meta) GetTransfer() *MetaTransfer

Get exportable metadata/data struct

func (*Meta) InvalidateIn

func (m *Meta) InvalidateIn(in time.Duration)

Set invalidation date via duration

func (*Meta) IsValid

func (m *Meta) IsValid() bool

wrapper for checking validity via metadata

func (*Meta) Key

func (m *Meta) Key() []byte

pass through a call to the Key method

func (*Meta) SetKey

func (m *Meta) SetKey(key []byte)

pass through a call to the SetKey method

func (*Meta) StoreID

func (m *Meta) StoreID() []byte

return StoreID

type MetaTransfer

type MetaTransfer struct {
	Metadata *Meta
	Record   *Item
}

For data import/export, we need to make the content accessible.

type NotifyPurge

type NotifyPurge struct {
	StoreID []byte
	Key     []byte
}

Jump to

Keyboard shortcuts

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