bolt

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

A simple kernel service wich provides access to a single github.com/etcd-io/bbolt object store

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltService

type BoltService struct {
	FileName string
	// contains filtered or unexported fields
}

func (*BoltService) Batch

func (s *BoltService) Batch(fn func(*Tx) error) error

Batch calls fn as part of a batch. It behaves similar to Update, except:

1. concurrent Batch calls can be combined into a single Bolt transaction.

2. the function passed to Batch may be called multiple times, regardless of whether it returns error or not.

This means that Batch function side effects must be idempotent and take permanent effect only after a successful return is seen in caller.

The maximum batch size and delay can be adjusted with DB.MaxBatchSize and DB.MaxBatchDelay, respectively.

Batch is only useful when there are multiple goroutines calling it.

func (*BoltService) Init

func (s *BoltService) Init(k *kernel.Kernel) error

func (*BoltService) Name

func (s *BoltService) Name() string

func (*BoltService) PostInit

func (s *BoltService) PostInit() error

func (*BoltService) Start

func (s *BoltService) Start() error

func (*BoltService) Stop

func (s *BoltService) Stop()

func (*BoltService) Update

func (s *BoltService) Update(fn func(*Tx) error) error

Update 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 Update() method.

func (*BoltService) View

func (s *BoltService) View(fn func(*Tx) error) error

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

type Bucket

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

func (*Bucket) Bucket

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

Bucket retrieves a nested bucket by name. Returns nil if the bucket does not exist. The bucket instance is only valid for the lifetime of the transaction.

func (*Bucket) CreateBucket

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

CreateBucket creates a new bucket at the given key and returns the new bucket. Returns an error if the key already exists, if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.

func (*Bucket) CreateBucketIfNotExists

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

CreateBucketIfNotExists creates a new bucket if it doesn't already exist and returns a reference to it. Returns an error if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.

func (*Bucket) Cursor

func (b *Bucket) Cursor() *Cursor

Cursor creates a cursor associated with the bucket. The cursor is only valid as long as the transaction is open. Do not use a cursor after the transaction is closed.

func (*Bucket) Delete

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

Delete removes a key from the bucket. If the key does not exist then nothing is done and a nil error is returned. Returns an error if the bucket was created from a read-only transaction.

func (*Bucket) DeleteBucket

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

DeleteBucket deletes a bucket at the given key. Returns an error if the bucket does not exists, or if the key represents a non-bucket value.

func (*Bucket) ForEach

func (b *Bucket) ForEach(fn func(k string, v []byte) error) error

ForEach executes a function for each key/value pair in a bucket. If the provided function returns an error then the iteration is stopped and the error is returned to the caller. The provided function must not modify the bucket; this will result in undefined behavior.

func (*Bucket) Get

func (b *Bucket) Get(key string) []byte

Get retrieves the value for a key in the bucket. Returns a nil value if the key does not exist or if the key is a nested bucket. The returned value is only valid for the life of the transaction.

func (*Bucket) GetJSON

func (b *Bucket) GetJSON(key string, val interface{}) bool

Get retrieves the value for a key in the bucket. Returns a nil value if the key does not exist or if the key is a nested bucket. The returned value is only valid for the life of the transaction.

func (*Bucket) NextSequence

func (b *Bucket) NextSequence() (uint64, error)

NextSequence returns an autoincrementing integer for the bucket.

func (*Bucket) Put

func (b *Bucket) Put(key string, value []byte) error

Put sets the value for a key in the bucket. If the key exist then its previous value will be overwritten. Supplied value must remain valid for the life of the transaction. Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.

func (*Bucket) PutJSON

func (b *Bucket) PutJSON(key string, value interface{}) error

Put sets the value for a key in the bucket. If the key exist then its previous value will be overwritten. Supplied value must remain valid for the life of the transaction. Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.

func (*Bucket) Sequence

func (b *Bucket) Sequence() uint64

Sequence returns the current integer for the bucket without incrementing it.

func (*Bucket) SetSequence

func (b *Bucket) SetSequence(v uint64) error

SetSequence updates the sequence number for the bucket.

func (*Bucket) Tx

func (b *Bucket) Tx() *Tx

Tx returns the tx of the bucket.

type Cursor

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

func (*Cursor) Bucket

func (c *Cursor) Bucket() *Bucket

Bucket returns the bucket that this cursor was created from.

func (*Cursor) Delete

func (c *Cursor) Delete() error

Delete removes the current key/value under the cursor from the bucket. Delete fails if current key/value is a bucket or if the transaction is not writable.

func (*Cursor) First

func (c *Cursor) First() (key string, value []byte)

First moves the cursor to the first item in the bucket and returns its key and value. If the bucket is empty then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

func (*Cursor) Last

func (c *Cursor) Last() (key string, value []byte)

Last moves the cursor to the last item in the bucket and returns its key and value. If the bucket is empty then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

func (*Cursor) Next

func (c *Cursor) Next() (key string, value []byte)

Next moves the cursor to the next item in the bucket and returns its key and value. If the cursor is at the end of the bucket then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

func (*Cursor) Prev

func (c *Cursor) Prev() (key string, value []byte)

Prev moves the cursor to the previous item in the bucket and returns its key and value. If the cursor is at the beginning of the bucket then a nil key and value are returned. The returned key and value are only valid for the life of the transaction.

func (*Cursor) Seek

func (c *Cursor) Seek(seek string) (key string, value []byte)

Seek moves the cursor to a given key and returns it. If the key does not exist then the next key is used. If no keys follow, a nil key is returned. The returned key and value are only valid for the life of the transaction.

type Tx

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

func (*Tx) Bucket

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

Bucket retrieves a bucket by name. Returns nil if the bucket does not exist. The bucket instance is only valid for the lifetime of the transaction.

func (*Tx) CreateBucket

func (t *Tx) CreateBucket(name string) (*Bucket, error)

CreateBucket creates a new bucket. Returns an error if the bucket already exists, if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.

func (*Tx) CreateBucketIfNotExists

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

CreateBucketIfNotExists creates a new bucket if it doesn't already exist. Returns an error if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.

func (*Tx) DeleteBucket

func (t *Tx) DeleteBucket(name string) error

DeleteBucket deletes a bucket. Returns an error if the bucket cannot be found or if the key represents a non-bucket value.

func (*Tx) ForEach

func (t *Tx) ForEach(fn func(k string, v *Bucket) error) error

ForEach iterates over all bucket names

func (*Tx) OnCommit

func (t *Tx) OnCommit(fn func())

OnCommit adds a handler function to be executed after the transaction successfully commits.

Jump to

Keyboard shortcuts

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