boltengine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package boltengine implements a BoltDB engine.

Example
dir, err := ioutil.TempDir("", "bolt")
if err != nil {
	log.Fatal(err)
}
defer os.RemoveAll(dir)

db, err := genji.Open(filepath.Join(dir, "my.db"))
if err != nil {
	log.Fatal(err)
}
defer db.Close()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	DB *bolt.DB
}

Engine represents a BoltDB engine. Each store is stored in a dedicated bucket.

func NewEngine

func NewEngine(path string, mode os.FileMode, opts *bolt.Options) (*Engine, error)

NewEngine creates a BoltDB engine. It takes the same argument as Bolt's Open function.

Example
dir, err := ioutil.TempDir("", "bolt")
if err != nil {
	log.Fatal(err)
}
defer os.RemoveAll(dir)

ng, err := boltengine.NewEngine(filepath.Join(dir, "genji.db"), 0o600, nil)
if err != nil {
	log.Fatal(err)
}

db, err := genji.New(context.Background(), ng)
if err != nil {
	log.Fatal(err)
}
defer db.Close()
Output:

func (*Engine) Begin

func (e *Engine) Begin(ctx context.Context, opts engine.TxOptions) (engine.Transaction, error)

Begin creates a transaction using Bolt's transaction API.

func (*Engine) Close

func (e *Engine) Close() error

Close the engine and underlying Bolt database.

type Store

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

A Store is an implementation of the engine.Store interface using a bucket.

func (*Store) Delete

func (s *Store) Delete(k []byte) error

Delete a record by key. If not found, returns table.ErrDocumentNotFound. It hides the key without deleting the actual node from the tree, to tree rebalancing during iterations. It then adds it to a sub bucket containing the list of keys to delete when the transaction is committed.

func (*Store) Get

func (s *Store) Get(k []byte) ([]byte, error)

Get returns a value associated with the given key. If not found, returns engine.ErrKeyNotFound.

func (*Store) Iterator

func (s *Store) Iterator(opts engine.IteratorOptions) engine.Iterator

Iterator uses the Bolt bucket cursor.

func (*Store) NextSequence

func (s *Store) NextSequence() (uint64, error)

NextSequence returns a monotonically increasing integer.

func (*Store) Put

func (s *Store) Put(k, v []byte) error

Put stores a key value pair. If it already exists, it overrides it.

func (*Store) Truncate

func (s *Store) Truncate() error

Truncate deletes all the records of the store.

type Transaction

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

A Transaction uses Bolt's transactions.

func (*Transaction) Commit

func (t *Transaction) Commit() error

Commit the transaction.

func (*Transaction) CreateStore

func (t *Transaction) CreateStore(name []byte) error

CreateStore creates a bolt bucket and returns a store. If the store already exists, returns engine.ErrStoreAlreadyExists.

func (*Transaction) DropStore

func (t *Transaction) DropStore(name []byte) error

DropStore deletes the underlying bucket.

func (*Transaction) GetStore

func (t *Transaction) GetStore(name []byte) (engine.Store, error)

GetStore returns a store by name. The store uses a Bolt bucket.

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

Rollback the transaction. Can be used safely after commit.

Jump to

Keyboard shortcuts

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