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 ¶
- type Engine
- type Store
- func (s *Store) AscendGreaterOrEqual(pivot []byte, fn func(k, v []byte) error) error
- func (s *Store) Delete(k []byte) error
- func (s *Store) DescendLessOrEqual(pivot []byte, fn func(k, v []byte) error) error
- func (s *Store) Get(k []byte) ([]byte, error)
- func (s *Store) Put(k, v []byte) error
- func (s *Store) Truncate() error
- type Transaction
- func (t *Transaction) Commit() error
- func (t *Transaction) CreateStore(name string) error
- func (t *Transaction) DropStore(name string) error
- func (t *Transaction) GetStore(name string) (engine.Store, error)
- func (t *Transaction) ListStores(prefix string) ([]string, error)
- func (t *Transaction) Rollback() error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
Engine represents a BoltDB engine. Each store is stored in a dedicated bucket.
func NewEngine ¶
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:
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 ¶
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) DescendLessOrEqual ¶
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 ¶
Get returns a value associated with the given key. If not found, returns engine.ErrKeyNotFound.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
A Transaction uses Bolt's transactions.
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.