batch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterCommitFunc

type AfterCommitFunc func(error) error

AfterCommitFunc is a handler for the after Commit hook

type AfterDeleteFunc

type AfterDeleteFunc func(datastore.Key, error) error

AfterDeleteFunc is a handler for the after Delete hook

type AfterPutFunc

type AfterPutFunc func(datastore.Key, []byte, error) error

AfterPutFunc is a handler for the after Put hook

type Batch

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

Batch is a group of Puts and Deletes to be performed (Committed) in one shot.

func NewBatch

func NewBatch(bch datastore.Batch, options ...Option) *Batch

NewBatch wraps a datastore.Batch and adds optional before and after hooks into it's methods.

func (*Batch) Commit

func (hbh *Batch) Commit() error

Commit submits the batch to the datastore for processing, it calls OnBeforeCommit and OnAfterCommit hooks.

func (*Batch) Delete

func (hbh *Batch) Delete(key datastore.Key) error

Delete removes the value for given `key`, it calls OnBeforeDelete and OnAfterDelete hooks.

func (*Batch) Put

func (hbh *Batch) Put(key datastore.Key, value []byte) error

Put stores the object `value` named by `key`, it calls OnBeforePut and OnAfterPut hooks.

type BeforeCommitFunc

type BeforeCommitFunc func()

BeforeCommitFunc is a handler for the before Commit hook

type BeforeDeleteFunc

type BeforeDeleteFunc func(datastore.Key) datastore.Key

BeforeDeleteFunc is a handler for the before Delete hook

type BeforePutFunc

type BeforePutFunc func(datastore.Key, []byte) (datastore.Key, []byte)

BeforePutFunc is a handler for the before Put hook

type Option

type Option func(*Options) error

Option is the batch option type.

func WithAfterCommit

func WithAfterCommit(f AfterCommitFunc) Option

WithAfterCommit configures a hook that is called _after_ Commit. Defaults to noop.

func WithAfterDelete

func WithAfterDelete(f AfterDeleteFunc) Option

WithAfterDelete configures a hook that is called _after_ Delete. Defaults to noop.

func WithAfterPut

func WithAfterPut(f AfterPutFunc) Option

WithAfterPut configures a hook that is called _after_ Put. Defaults to noop.

func WithBeforeCommit

func WithBeforeCommit(f BeforeCommitFunc) Option

WithBeforeCommit configures a hook that is called _before_ Commit. Defaults to noop.

func WithBeforeDelete

func WithBeforeDelete(f BeforeDeleteFunc) Option

WithBeforeDelete configures a hook that is called _before_ Delete. Defaults to noop.

func WithBeforePut

func WithBeforePut(f BeforePutFunc) Option

WithBeforePut configures a hook that is called _before_ Put. Defaults to noop.

type Options

type Options struct {
	BeforePut    BeforePutFunc
	AfterPut     AfterPutFunc
	BeforeDelete BeforeDeleteFunc
	AfterDelete  AfterDeleteFunc
	BeforeCommit BeforeCommitFunc
	AfterCommit  AfterCommitFunc
}

Options are batch options.

func (*Options) Apply

func (o *Options) Apply(opts ...Option) error

Apply applies the given options to this Option.

Jump to

Keyboard shortcuts

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