boltengine

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 boltengine implements a BoltDB engine.

Example
package main

import (
	"io/ioutil"
	"log"
	"os"
	"path"

	"github.com/asdine/genji"
)

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

	db, err := genji.Open(path.Join(dir, "my.db"))
	defer db.Close()
	if err != nil {
		log.Fatal(err)
	}
}
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
package main

import (
	"io/ioutil"
	"log"
	"os"
	"path"

	"github.com/asdine/genji"
	"github.com/asdine/genji/engine/boltengine"
)

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

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

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

func (*Engine) Begin

func (e *Engine) Begin(writable bool) (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) 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 table.ErrDocumentNotFound.

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 Bolt'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 bolt bucket and returns a store. If the store already exists, returns engine.ErrStoreAlreadyExists.

func (*Transaction) DropStore

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

DropStore deletes the underlying bucket.

func (*Transaction) GetStore added in v0.5.0

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

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

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