badgerengine

package module
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: 5 Imported by: 2

Documentation

Overview

Package badgerengine implements a Badger engine.

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

ng, err := badgerengine.NewEngine(badger.DefaultOptions(filepath.Join(dir, "badger")))
if err != nil {
	log.Fatal(err)
}

db, err := genji.New(context.Background(), ng)
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 *badger.DB
}

Engine represents a Badger engine.

func NewEngine

func NewEngine(opt badger.Options) (*Engine, error)

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

func (*Engine) Begin

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

Begin creates a transaction using Badger's transaction API.

func (*Engine) Close

func (e *Engine) Close() error

Close the engine and underlying Badger database.

type Store

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

A Store is an implementation of the engine.Store interface.

func (*Store) Delete

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

Delete a record by key. If not found, returns engine.ErrKeyNotFound.

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 a Badger iterator with default options. Only one iterator is allowed per read-write transaction.

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 Badger'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 store. If the store already exists, returns engine.ErrStoreAlreadyExists.

func (*Transaction) DropStore

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

DropStore deletes the store and all its keys.

func (*Transaction) GetStore

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

GetStore returns a store by name.

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