kvdb

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package kvdb provides a kvdb interface

Index

Constants

View Source
const (
	// OptionExpires is the key kvdb providers should use to set expiration as a time.Duration
	OptionExpires = "expires"

	// OptionDB is the database name
	OptionDB = "db"

	// OptionPrefix is the prefix the provider should apply to keys
	OptionPrefix = "prefix"

	// OptionReadOnly opens the provider in readonly mode
	OptionReadOnly = "readonly"

	// OptionMetadata allows adding additional key/value to the object
	OptionMetadata = "metadata"

	// OptionKeyTransform provides a func(string)string to transform the key
	OptionKeyTransform = "key-transform"

	// OptionValueGetTransform provides a func([]byte])[]byte to transform the value
	OptionValueGetTransform = "value-transform"

	// HTTPOptionMethod specifies the method access for the link
	HTTPOptionMethod = "method"
)

Variables

View Source
var (
	// ErrObjectStoreNotFound is returned when an object store does not exist
	ErrObjectStoreNotFound = errors.New("store not found")

	// ErrObjectNotFound is returned when a object does not exist
	ErrObjectNotFound = errors.New("object not found")

	// ErrNotSupported is returned when a provider does not suport the operation
	ErrNotSupported = errors.New("not supported")

	// ErrForEachBreak is used to make ForEach stop without an error
	ErrForEachBreak = errors.New("break from foreach loop")

	// ErrReadOnly is returned when the provider is readonly
	ErrReadOnly = errors.New("provider is opened for read-only access")
)

Functions

func RegisterProvider

func RegisterProvider(name string, provider NewFunc)

RegisterProvider makes a database provider available by the provided name. If RegisterProvider is called twice with the same name or if provider is nil, it panics.

Types

type DB added in v2.1.2

type DB struct {
	Provider
	// contains filtered or unexported fields
}

DB is the kvdb handle

func MustOpen

func MustOpen(uri string, p ...types.StringMap) *DB

MustOpen will panic on fail

func Open

func Open(uri string, p ...types.StringMap) (*DB, error)

Open opens a new auth provider

func (*DB) Attributes added in v2.1.2

func (db *DB) Attributes(key string) (types.StringMap, error)

Attributes returns provider specific data about the object

func (*DB) Copy added in v2.1.4

func (db *DB) Copy(src string, dst string, params ...types.StringMap) error

Copy will copy one key to another

func (*DB) Delete added in v2.1.2

func (db *DB) Delete(key string, params ...types.StringMap) error

Delete deletes an object for the key

func (*DB) ForEach added in v2.1.2

func (db *DB) ForEach(prefix string, handler func(key string) error) error

ForEach iterates over the keys in a kvdb

func (*DB) Get added in v2.1.2

func (db *DB) Get(key string, params ...types.StringMap) ([]byte, error)

Get returns an io.Reader that allows for getting the object data

func (*DB) Lock added in v2.1.4

func (db *DB) Lock(key string, handler func(key string) error, params ...types.StringMap) error

Lock will lock the key

func (*DB) OnMiss added in v2.1.2

func (db *DB) OnMiss(handler func(key string, params ...types.StringMap) ([]byte, error), update bool)

OnMiss allows for handling missing data to be fetched externally and updated

func (*DB) OnUpdate added in v2.1.2

func (db *DB) OnUpdate(handler func(key string, val []byte, params ...types.StringMap) error, passthru bool)

OnUpdate is called when a value is updated successfully in the store

func (*DB) Put added in v2.1.2

func (db *DB) Put(key string, val []byte, params ...types.StringMap) error

Put set the value, serializing if necessary

func (*DB) Size added in v2.1.2

func (db *DB) Size(key string) (int64, error)

Size returns the size of the object

func (*DB) URI added in v2.1.4

func (db *DB) URI(key string, params ...types.StringMap) (string, error)

URI returns an accessible URI for the key

type NewFunc

type NewFunc func(name string, params types.StringMap) (Provider, error)

NewFunc intializes the provider

type Provider

type Provider interface {
	// Get returns an io.Reader that allows for getting the object data
	Get(key string, params ...types.StringMap) ([]byte, error)

	// Put set the value, serializing if necessary
	Put(key string, val []byte, params ...types.StringMap) error

	// Delete deletes the key
	Delete(key string, params ...types.StringMap) error

	// Copy will copy one key to another
	Copy(src string, dst string, params ...types.StringMap) error

	// Lock will lock the key can call the handler and unlock after return
	Lock(key string, handler func(key string) error, params ...types.StringMap) error

	// URI returns an accessible URI for the key
	URI(key string, params ...types.StringMap) (string, error)

	// Attributes returns provider specific data about the object
	Attributes(key string) (types.StringMap, error)

	// Size returns the size of the object
	Size(key string) (int64, error)

	// ForEach iterates over the keys in a kvdb
	ForEach(prefix string, handler func(key string) error) error

	// PathSeparator is the string used to separate key paths for the provider
	PathSeparator() string

	// Name returns the object store name
	Name() string
}

Provider is an interface for kv object stores implemented by providers

Directories

Path Synopsis
Package providers bootstraps all of the providers
Package providers bootstraps all of the providers
env
Package env provides an os.Environment provider transient kvdb
Package env provides an os.Environment provider transient kvdb
mem
Package mem provides an in-memory transient kvdb
Package mem provides an in-memory transient kvdb
s3

Jump to

Keyboard shortcuts

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