shock

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: MIT Imports: 6 Imported by: 0

README

Shock

A wrapper around BBolt.

Check out the docs or an example.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{
	Bolt:       bbolt.DefaultOptions,
	Serializer: JSONSerializer{},
}

DefaultOptions are the default options used to init Shock

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Name string
	DB   *DB
}

Bucket is a shorthand way to group a database bucket together

func (*Bucket) Count

func (b *Bucket) Count() (int, error)

Count returns the number of objects in the bucket

func (*Bucket) Get

func (b *Bucket) Get(id, val interface{}) error

Get returns a value from the bucket with the specified sequence ID

func (*Bucket) Init added in v0.0.4

func (b *Bucket) Init() error

Init initializes the bucket if it doesn't exist

func (*Bucket) Put

func (b *Bucket) Put(val Sequencer) error

Put adds a new value to the bucket

func (*Bucket) PutWithKey added in v0.0.3

func (b *Bucket) PutWithKey(key, val interface{}) error

PutWithKey adds a new value with the specified key to the bucket

func (*Bucket) UpdateEach

func (b *Bucket) UpdateEach(fn EachFunc) error

UpdateEach iterates over each object in the bucket in write mode

func (*Bucket) ViewEach

func (b *Bucket) ViewEach(fn EachFunc) error

ViewEach iterates over each object in the bucket in read-only mode

type DB

type DB struct {
	Bolt       *bbolt.DB
	Serializer Serializer
}

DB is a Shock (BBolt) database

func Open

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

Open creates a connection to a database file

func (*DB) Bucket

func (d *DB) Bucket(name string) *Bucket

Bucket returns a shorthand wrapper for interacting with a specific bucket

func (*DB) Count

func (d *DB) Count(bucket string) (int, error)

Count returns the number of objects in a bucket

func (*DB) Get

func (d *DB) Get(bucket string, id, val interface{}) error

Get returns a value from a bucket with the specified sequence ID

func (*DB) Init added in v0.0.4

func (d *DB) Init(buckets ...string) error

Init initializes buckets if they don't exist

func (*DB) Put

func (d *DB) Put(bucket string, val Sequencer) error

Put adds a new value to a bucket

func (*DB) PutWithKey added in v0.0.3

func (d *DB) PutWithKey(bucket string, key, val interface{}) error

PutWithKey adds a new value to the bucket with a defined key

func (*DB) UpdateEach

func (d *DB) UpdateEach(bucket string, fn EachFunc) error

UpdateEach iterates over each object in a bucket in write mode

func (*DB) ViewEach

func (d *DB) ViewEach(bucket string, fn EachFunc) error

ViewEach iterates over each object in a bucket in read-only mode

type EachFunc

type EachFunc func(id, serial []byte) error

EachFunc defines a way to interact with each object in a bucket while iterating

type GobSerializer added in v0.0.4

type GobSerializer struct{}

GobSerializer is a Serializer that uses gob

func (GobSerializer) Marshal added in v0.0.4

func (g GobSerializer) Marshal(v interface{}) ([]byte, error)

Marshal encodes an object to gob

func (GobSerializer) Unmarshal added in v0.0.4

func (g GobSerializer) Unmarshal(data []byte, v interface{}) error

Unmarshal decodes an object from gob

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer is a Serializer that uses JSON

func (JSONSerializer) Marshal

func (j JSONSerializer) Marshal(v interface{}) ([]byte, error)

Marshal encodes an object to JSON

func (JSONSerializer) Unmarshal

func (j JSONSerializer) Unmarshal(data []byte, v interface{}) error

Unmarshal decodes an object from JSON

type Options

type Options struct {
	Bolt       *bbolt.Options
	Serializer Serializer
}

Options are Shock init options

type Sequencer

type Sequencer interface {
	AssignSeq(uint64)
}

Sequencer defines a way to assign a unique sequence ID to an object

type Serializer

type Serializer interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

Serializer defines a way to encode/decode objects in the database

Jump to

Keyboard shortcuts

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