kv

package
v0.0.0-...-d500d3c Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Note: this file is used as a proof of concept for having a generic keyvalue store backed by specific implementations of kv.Store.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is the error returned when the key requested is not found.
	ErrKeyNotFound = errors.New("key not found")
	// ErrTxNotWritable is the error returned when an mutable operation is called during
	// a non-writable transaction.
	ErrTxNotWritable = errors.New("transaction is not writable")
)

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	Get(key []byte) ([]byte, error)
	Cursor() (Cursor, error)
	// Put should error if the transaction it was called in is not writable.
	Put(key, value []byte) error
	// Delete should error if the transaction it was called in is not writable.
	Delete(key []byte) error
}

Bucket is the abstraction used to perform get/put/delete/get-many operations in a key value store.

type Cursor

type Cursor interface {
	Seek(prefix []byte) (k []byte, v []byte)
	First() (k []byte, v []byte)
	Last() (k []byte, v []byte)
	Next() (k []byte, v []byte)
	Prev() (k []byte, v []byte)
}

Cursor is an abstraction for iterating/ranging through data. A concrete implementation of a cursor can be found in cursor.go.

func NewStaticCursor

func NewStaticCursor(pairs []Pair) Cursor

NewStaticCursor returns an instance of a StaticCursor. It destructively sorts the provided pairs to be in key ascending order.

type ExampleService

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

ExampleService is an example user like service built on a generic kv store.

func NewExampleService

func NewExampleService(kv Store, idGen platform.IDGenerator) *ExampleService

NewExampleService creates an instance of an example service.

func (*ExampleService) CreateUser

func (c *ExampleService) CreateUser(ctx context.Context, u *platform.User) error

CreateUser creates a platform example and sets b.ID.

func (*ExampleService) DeleteUser

func (c *ExampleService) DeleteUser(ctx context.Context, id platform.ID) error

DeleteUser deletes a example and prunes it from the index.

func (*ExampleService) FindUser

func (c *ExampleService) FindUser(ctx context.Context, filter platform.UserFilter) (*platform.User, error)

FindUser retrives a example using an arbitrary example filter. Filters using ID, or Name should be efficient. Other filters will do a linear scan across examples until it finds a match.

func (*ExampleService) FindUserByID

func (c *ExampleService) FindUserByID(ctx context.Context, id platform.ID) (*platform.User, error)

FindUserByID retrieves a example by id.

func (*ExampleService) FindUserByName

func (c *ExampleService) FindUserByName(ctx context.Context, n string) (*platform.User, error)

FindUserByName returns a example by name for a particular example.

func (*ExampleService) FindUsers

func (c *ExampleService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error)

FindUsers retrives all examples that match an arbitrary example filter. Filters using ID, or Name should be efficient. Other filters will do a linear scan across all examples searching for a match.

func (*ExampleService) Initialize

func (c *ExampleService) Initialize() error

Initialize creates the buckets for the example service

func (*ExampleService) PutUser

func (c *ExampleService) PutUser(ctx context.Context, u *platform.User) error

PutUser will put a example without setting an ID.

func (*ExampleService) UpdateUser

func (c *ExampleService) UpdateUser(ctx context.Context, id platform.ID, upd platform.UserUpdate) (*platform.User, error)

UpdateUser updates a example according the parameters set on upd.

type Pair

type Pair struct {
	Key   []byte
	Value []byte
}

Pair is a struct for key value pairs.

type Store

type Store interface {
	// View opens up a transaction that will not write to any data. Implementing interfaces
	// should take care to ensure that all view transactions do not mutate any data.
	View(func(Tx) error) error
	// Update opens up a transaction that will mutate data.
	Update(func(Tx) error) error
}

Store is an interface for a generic key value store. It is modeled after the boltdb database struct.

type Tx

type Tx interface {
	Bucket(b []byte) (Bucket, error)
	Context() context.Context
	WithContext(ctx context.Context)
}

Tx is a transaction in the store.

Jump to

Keyboard shortcuts

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