2020-03-12 16:41:30 +03:00
|
|
|
// Package store is an interface for distributed data storage.
|
2020-07-14 15:13:32 +03:00
|
|
|
// The design document is located at https://github.com/micro/development/blob/master/design/framework/store.md
|
2019-06-12 09:46:20 +03:00
|
|
|
package store
|
2019-05-31 02:43:23 +03:00
|
|
|
|
|
|
|
import (
|
2020-09-17 15:15:42 +03:00
|
|
|
"context"
|
2019-05-31 02:43:23 +03:00
|
|
|
"errors"
|
2020-12-10 22:08:56 +03:00
|
|
|
|
|
|
|
"github.com/unistack-org/micro/v3/metadata"
|
2019-05-31 02:43:23 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-03-12 16:41:30 +03:00
|
|
|
// ErrNotFound is returned when a key doesn't exist
|
2020-11-03 01:08:23 +03:00
|
|
|
ErrNotFound = errors.New("not found")
|
|
|
|
// DefaultStore is the global default store
|
|
|
|
DefaultStore Store = NewStore()
|
2019-05-31 02:43:23 +03:00
|
|
|
)
|
|
|
|
|
2019-06-12 09:46:20 +03:00
|
|
|
// Store is a data storage interface
|
|
|
|
type Store interface {
|
2020-11-06 00:03:40 +03:00
|
|
|
// Init initialises the store
|
2020-10-16 09:38:57 +03:00
|
|
|
Init(opts ...Option) error
|
2020-11-03 01:08:23 +03:00
|
|
|
// Connect is used when store needs to be connected
|
2020-10-16 09:38:57 +03:00
|
|
|
Connect(ctx context.Context) error
|
2020-03-12 16:41:30 +03:00
|
|
|
// Options allows you to view the current options.
|
|
|
|
Options() Options
|
2020-12-10 22:08:56 +03:00
|
|
|
// Exists check that key exists in store
|
|
|
|
Exists(ctx context.Context, key string) 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
|
2020-03-12 16:41:30 +03:00
|
|
|
// Delete removes the record with the corresponding key from the store.
|
2020-09-17 15:15:42 +03:00
|
|
|
Delete(ctx context.Context, key string, opts ...DeleteOption) error
|
2020-03-12 16:41:30 +03:00
|
|
|
// List returns any keys that match, or an empty list with no error if none matched.
|
2020-09-17 15:15:42 +03:00
|
|
|
List(ctx context.Context, opts ...ListOption) ([]string, error)
|
2020-10-16 09:38:57 +03:00
|
|
|
// Disconnect the store
|
|
|
|
Disconnect(ctx context.Context) error
|
2020-04-02 01:27:15 +03:00
|
|
|
// String returns the name of the implementation.
|
|
|
|
String() string
|
2019-05-31 02:43:23 +03:00
|
|
|
}
|
|
|
|
|
2020-12-10 22:08:56 +03:00
|
|
|
// Value is an item stored or retrieved from a Store
|
|
|
|
// may be used in store implementations to provide metadata
|
|
|
|
type Value struct {
|
|
|
|
// Data holds underline struct
|
|
|
|
Data interface{} `json:"data"`
|
|
|
|
// Metadata associated with data for indexing
|
|
|
|
Metadata metadata.Metadata `json:"metadata"`
|
2019-05-31 02:43:23 +03:00
|
|
|
}
|