bolts

package
v0.0.0-...-147f0cf Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BBoltCursor

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

BBoltCursor is a wrapper around the bbolt cursor to map to the IBucketCursor API and to ensure its transaction is released after the cursor is no longer used. This implements the IBucketCursor API

func NewBBoltCursor

func NewBBoltCursor(ctx context.Context, bucketID string, bucket *bbolt.Bucket) *BBoltCursor

func (*BBoltCursor) BucketID

func (bbc *BBoltCursor) BucketID() string

func (*BBoltCursor) Context

func (bbc *BBoltCursor) Context() context.Context

Context returns the cursor application context

func (*BBoltCursor) First

func (bbc *BBoltCursor) First() (key string, value []byte, valid bool)

First moves the cursor to the first item

func (*BBoltCursor) Last

func (bbc *BBoltCursor) Last() (key string, value []byte, valid bool)

Last moves the cursor to the last item

func (*BBoltCursor) Next

func (bbc *BBoltCursor) Next() (key string, value []byte, valid bool)

Next iterates to the next key from the current cursor

func (*BBoltCursor) NextN

func (bbc *BBoltCursor) NextN(steps uint) (docs map[string][]byte, itemsRemaining bool)

NextN increases the cursor position N times and return the encountered key-value pairs

func (*BBoltCursor) Prev

func (bbc *BBoltCursor) Prev() (key string, value []byte, valid bool)

Prev iterations to the previous key from the current cursor

func (*BBoltCursor) PrevN

func (bbc *BBoltCursor) PrevN(steps uint) (docs map[string][]byte, itemsRemaining bool)

PrevN decreases the cursor position N times and return the encountered key-value pairs

func (*BBoltCursor) Release

func (bbc *BBoltCursor) Release()

Release the cursor This ends the bbolt bbBucket transaction

func (*BBoltCursor) Seek

func (bbc *BBoltCursor) Seek(searchKey string) (key string, value []byte, valid bool)

Seek returns a cursor with Next() and Prev() iterators

type BoltBucket

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

BoltBucket implements the IBucket API using the embedded bolt database This bbBucket differs from bolt buckets in that transactions are created for read/write operations. This means that bbolt buckets are created and released continuously as needed.

func NewBoltBucket

func NewBoltBucket(clientID, bucketID string, db *bbolt.DB, onRelease func(bucket buckets.IBucket)) *BoltBucket

NewBoltBucket creates a new bbBucket

clientID that owns the bbBucket. Used for logging
bucketID used to create transactional buckets
db bbolt database used to create transactions
onRelease callback to track reference for detecting unreleased buckets on close

func (*BoltBucket) Close

func (bb *BoltBucket) Close() (err error)

Close the bbBucket

func (*BoltBucket) Cursor

func (bb *BoltBucket) Cursor(ctx context.Context) (cursor buckets.IBucketCursor, err error)

Cursor returns a new cursor for iterating the bbBucket. This creates a read-only bbolt bbBucket for iteration. The cursor MUST be closed after use to release the bbolt bbBucket. Do not write to the database while iterating.

ctx is the application context available throught the cursor Context() method

This returns a cursor with Next() and Prev() iterators or an error if the bbBucket doesn't exist

func (*BoltBucket) Delete

func (bb *BoltBucket) Delete(key string) (err error)

Delete a key in the bbBucket

func (*BoltBucket) Get

func (bb *BoltBucket) Get(key string) (val []byte, err error)

Get reads a document with the given key returns nil if the key doesn't exist

func (*BoltBucket) GetMultiple

func (bb *BoltBucket) GetMultiple(keys []string) (docs map[string][]byte, err error)

GetMultiple returns a batch of documents with existing keys

func (*BoltBucket) ID

func (bb *BoltBucket) ID() string

ID returns the bbBucket's ID

func (*BoltBucket) Info

func (bb *BoltBucket) Info() (info *buckets.BucketStoreInfo)

Info returns the bbBucket info

func (*BoltBucket) Set

func (bb *BoltBucket) Set(key string, value []byte) (err error)

Set writes a document with the given key

func (*BoltBucket) SetMultiple

func (bb *BoltBucket) SetMultiple(docs map[string][]byte) (err error)

SetMultiple writes a multiple documents in a single transaction This returns an error as soon as an invalid key is encountered. Cancel this bbBucket with Close(false) if this returns an error.

type BoltStore

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

func NewBoltStore

func NewBoltStore(clientID, storePath string) *BoltStore

NewBoltStore creates a bbBucket store supporting the IBucketStore API using the embedded BBolt database

storePath is the file holding the database

func (*BoltStore) Close

func (store *BoltStore) Close() (err error)

Close the store and flush changes to disk Since boltDB locks transactions on close, this runs in the background. Close() returns before closing is completed.

func (*BoltStore) GetBucket

func (store *BoltStore) GetBucket(bucketID string) (bucket buckets.IBucket)

GetBucket returns a bbBucket to use for writing to storage. This does not yet create the bbBucket in the database until an operation takes place on the bbBucket.

func (*BoltStore) Open

func (store *BoltStore) Open() (err error)

Open the store

Jump to

Keyboard shortcuts

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