store

package
v3.3.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package store is an interface for distributed data storage. The design document is located at https://github.com/micro/development/blob/master/design/framework/store.md

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a key doesn't exist
	ErrNotFound = errors.New("not found")
	// ErrInvalidKey is returned when a key has empty or have invalid format
	ErrInvalidKey = errors.New("invalid key")
	// DefaultStore is the global default store
	DefaultStore Store = NewStore()
)

Functions

func NewContext added in v3.1.0

func NewContext(ctx context.Context, c Store) context.Context

NewContext put store in context

Types

type DeleteOption

type DeleteOption func(d *DeleteOptions)

DeleteOption sets values in DeleteOptions

func DeleteFrom

func DeleteFrom(database, table string) DeleteOption

DeleteFrom the database and table

func SetDeleteOption added in v3.1.8

func SetDeleteOption(k, v interface{}) DeleteOption

SetDeleteOption returns a function to setup a context with given value

type DeleteOptions

type DeleteOptions struct {
	// Context holds external options
	Context context.Context
	// Database holds database name
	Database string
	// Table holds table name
	Table string
	// Namespace holds namespace
	Namespace string
}

DeleteOptions configures an individual Delete operation

func NewDeleteOptions added in v3.1.0

func NewDeleteOptions(opts ...DeleteOption) DeleteOptions

NewDeleteOptions fills DeleteOptions struct with opts slice

type ExistsOption added in v3.1.8

type ExistsOption func(*ExistsOptions)

ExistsOption specifies Exists call options

func SetExistsOption added in v3.1.8

func SetExistsOption(k, v interface{}) ExistsOption

SetExistsOption returns a function to setup a context with given value

type ExistsOptions added in v3.1.8

type ExistsOptions struct {
	// Context holds external options
	Context context.Context
	// Namespace contains namespace
	Namespace string
}

ExistsOptions holds options for Exists method

func NewExistsOptions added in v3.1.8

func NewExistsOptions(opts ...ExistsOption) ExistsOptions

NewExistsOptions helper for Exists method

type ListOption

type ListOption func(l *ListOptions)

ListOption sets values in ListOptions

func ListFrom

func ListFrom(database, table string) ListOption

ListFrom the database and table

func ListLimit

func ListLimit(l uint) ListOption

ListLimit limits the number of returned keys to l

func ListOffset

func ListOffset(o uint) ListOption

ListOffset starts returning responses from o. Use in conjunction with Limit for pagination.

func ListPrefix

func ListPrefix(p string) ListOption

ListPrefix returns all keys that are prefixed with key

func ListSuffix

func ListSuffix(s string) ListOption

ListSuffix returns all keys that end with key

func SetListOption added in v3.1.8

func SetListOption(k, v interface{}) ListOption

SetListOption returns a function to setup a context with given value

type ListOptions

type ListOptions struct {
	Context   context.Context
	Database  string
	Prefix    string
	Suffix    string
	Namespace string
	Table     string
	Limit     uint
	Offset    uint
}

ListOptions configures an individual List operation

func NewListOptions added in v3.1.0

func NewListOptions(opts ...ListOption) ListOptions

NewListOptions fills ListOptions struct with opts slice

type Option

type Option func(o *Options)

Option sets values in Options

func Codec added in v3.1.0

func Codec(c codec.Codec) Option

Codec sets the codec

func Context

func Context(ctx context.Context) Option

Context pass context to store

func Database

func Database(db string) Option

Database allows multiple isolated stores to be kept in one backend, if supported.

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter added in v3.1.6

func Meter(m meter.Meter) Option

Meter sets the meter

func Name added in v3.2.1

func Name(n string) Option

Name the name

func Nodes

func Nodes(a ...string) Option

Nodes contains the addresses or other connection information of the backing storage. For example, an etcd implementation would contain the nodes of the cluster. A SQL implementation could contain one or more connection strings.

func SetOption added in v3.1.0

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func TLSConfig added in v3.1.8

func TLSConfig(t *tls.Config) Option

TLSConfig specifies a *tls.Config

func Table

func Table(t string) Option

Table is analag for a table in database backends or a key prefix in KV backends

func Tracer added in v3.1.6

func Tracer(t tracer.Tracer) Option

Tracer sets the tracer

type Options

type Options struct {
	// Meter used for metrics
	Meter meter.Meter
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Context holds external options
	Context context.Context
	// Codec used to marshal/unmarshal
	Codec codec.Codec
	// Logger used for logging
	Logger logger.Logger
	// TLSConfig holds tls.TLSConfig options
	TLSConfig *tls.Config
	// Name specifies store name
	Name string
	// Database specifies store database
	Database string
	// Table specifies store table
	Table string
	// Nodes contains store address
	// TODO: replace with Addrs
	Nodes []string
}

Options contains configuration for the Store

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions creates options struct

type ReadOption

type ReadOption func(r *ReadOptions)

ReadOption sets values in ReadOptions

func ReadFrom

func ReadFrom(database, table string) ReadOption

ReadFrom the database and table

func SetReadOption added in v3.1.8

func SetReadOption(k, v interface{}) ReadOption

SetReadOption returns a function to setup a context with given value

type ReadOptions

type ReadOptions struct {
	// Context holds external options
	Context context.Context
	// Database holds the database name
	Database string
	// Table holds table name
	Table string
	// Namespace holds namespace
	Namespace string
}

ReadOptions configures an individual Read operation

func NewReadOptions added in v3.1.0

func NewReadOptions(opts ...ReadOption) ReadOptions

NewReadOptions fills ReadOptions struct with opts slice

type Store

type Store interface {
	Name() string
	// Init initialises the store
	Init(opts ...Option) error
	// Connect is used when store needs to be connected
	Connect(ctx context.Context) error
	// Options allows you to view the current options.
	Options() Options
	// Exists check that key exists in store
	Exists(ctx context.Context, key string, opts ...ExistsOption) error
	// Read reads a single key name to provided value with optional ReadOptions
	Read(ctx context.Context, key string, val interface{}, opts ...ReadOption) error
	// Write writes a value to key name to the store with optional WriteOption
	Write(ctx context.Context, key string, val interface{}, opts ...WriteOption) error
	// Delete removes the record with the corresponding key from the store.
	Delete(ctx context.Context, key string, opts ...DeleteOption) error
	// List returns any keys that match, or an empty list with no error if none matched.
	List(ctx context.Context, opts ...ListOption) ([]string, error)
	// Disconnect the store
	Disconnect(ctx context.Context) error
	// String returns the name of the implementation.
	String() string
}

Store is a data storage interface

func FromContext added in v3.1.0

func FromContext(ctx context.Context) (Store, bool)

FromContext get store from context

func NewStore

func NewStore(opts ...Option) Store

NewStore returns a memory store

type Value added in v3.1.0

type Value struct {
	// Data holds underline struct
	Data interface{} `json:"data"`
	// Metadata associated with data for indexing
	Metadata metadata.Metadata `json:"metadata"`
}

Value is an item stored or retrieved from a Store may be used in store implementations to provide metadata

type WriteOption

type WriteOption func(w *WriteOptions)

WriteOption sets values in WriteOptions

func SetWriteOption added in v3.1.8

func SetWriteOption(k, v interface{}) WriteOption

SetWriteOption returns a function to setup a context with given value

func WriteMetadata added in v3.1.0

func WriteMetadata(md metadata.Metadata) WriteOption

WriteMetadata add metadata.Metadata

func WriteTTL

func WriteTTL(d time.Duration) WriteOption

WriteTTL is the time the record expires

func WriteTo

func WriteTo(database, table string) WriteOption

WriteTo the database and table

type WriteOptions

type WriteOptions struct {
	// Context holds external options
	Context context.Context
	// Metadata contains additional metadata
	Metadata metadata.Metadata
	// Database holds database name
	Database string
	// Table holds table name
	Table string
	// Namespace holds namespace
	Namespace string
	// TTL specifies key TTL
	TTL time.Duration
}

WriteOptions configures an individual Write operation

func NewWriteOptions added in v3.1.0

func NewWriteOptions(opts ...WriteOption) WriteOptions

NewWriteOptions fills WriteOptions struct with opts slice

Jump to

Keyboard shortcuts

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