badgerengine

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 4 Imported by: 0

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(path.Join(dir, "badger")))
if err != nil {
	log.Fatal(err)
}

db, err := genji.New(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(writable bool) (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) AscendGreaterOrEqual

func (s *Store) AscendGreaterOrEqual(pivot []byte, fn func(k, v []byte) error) error

AscendGreaterOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in increasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the beginning.

func (*Store) Delete

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

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

func (*Store) DescendLessOrEqual

func (s *Store) DescendLessOrEqual(pivot []byte, fn func(k, v []byte) error) error

DescendLessOrEqual seeks for the pivot and then goes through all the subsequent key value pairs in descreasing order and calls the given function for each pair. If the given function returns an error, the iteration stops and returns that error. If the pivot is nil, starts from the end.

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) 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 string) error

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

func (*Transaction) DropStore

func (t *Transaction) DropStore(name string) error

DropStore deletes the store and all its keys.

func (*Transaction) GetStore

func (t *Transaction) GetStore(name string) (engine.Store, error)

GetStore returns a store by name.

func (*Transaction) ListStores

func (t *Transaction) ListStores(prefix string) ([]string, error)

ListStores returns a list of all the store names.

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