kvdb

package module
v0.0.0-...-bb256a3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExists is returned when an object exists
	ErrExists = errors.New("exists")
	// ErrNotFound is returned when an object is not found
	ErrNotFound = errors.New("not found")
)

Functions

func NewBadgerDB

func NewBadgerDB(datadir string) (*badger.DB, error)

NewBadgerDB opens a new badger db handle from the given directory

Types

type DB

type DB interface {
	CreateTable(name string, obj Object) (Table, error)
	GetTable(name string, obj Object) (Table, error)
	GetTableVersion(string, ObjectVersion, func() hash.Hash) (TableVersion, error)
}

DB implements a logical grouping of tables

type Datastore

type Datastore interface {
	CreateDB(name string) DB
	GetDB(name string) DB
}

Datastore implements a store containing dbs

func NewBadgerDatastore

func NewBadgerDatastore(dir string, logger *log.Logger) (Datastore, error)

NewBadgerDatastore returns a badger backed datastore

func NewBadgerDatastoreFromDB

func NewBadgerDatastoreFromDB(db *badger.DB, logger *log.Logger) Datastore

NewBadgerDatastoreFromDB returns a badger backed datastore

func Open

func Open(dburl string, logger *log.Logger) (Datastore, error)

Open opens a datastore at the given url. The url scheme must contain the backend identifier as it is used to determine the driver to load e.g. badger:///path/to/db

type Object

type Object interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	New() Object
}

Object implements a storable object in the datastore

type ObjectVersion

type ObjectVersion interface {
	// Previous should return the hash of the previous version of the
	// object. It should return nil if this is the first and only version
	PreviousDigest() digest.Digest
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	New() ObjectVersion
	Hash(h hash.Hash)
}

ObjectVersion implements an interface for object versioning support

type Table

type Table interface {
	Create(id []byte, obj Object) error
	Get(id []byte) (Object, error)
	Update(id []byte, obj Object) error
	Delete(id []byte) error
	Iter(start []byte, callback func(Object) error) error
}

Table implements a collection of data structures of a given type

type TableVersion

type TableVersion interface {
	// Returns the object hash and/or error
	Create(id []byte, obj ObjectVersion) ([]byte, error)
	// Returns the obj and object hash
	Get(id []byte) (ObjectVersion, []byte, error)
	// Returns the object hash and/or error
	Update(id []byte, obj ObjectVersion) ([]byte, error)
	// Deletes the object of the id and returns the object hash and/or error
	Delete(id []byte) ([]byte, error)
	// Iterate over the active Objects
	Iter([]byte, func(ObjectVersion) error) error
	// Iterate over each reference.
	IterRef([]byte, func(h []byte) error) error
}

TableVersion implements a colloection of versioned data structures of a given type

Jump to

Keyboard shortcuts

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