2020-03-12 16:41:30 +03:00
|
|
|
// Package store is an interface for distributed data storage.
|
2021-10-02 19:55:07 +03:00
|
|
|
package store // import "go.unistack.org/micro/v3/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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
2021-01-26 02:08:22 +03:00
|
|
|
// ErrInvalidKey is returned when a key has empty or have invalid format
|
|
|
|
ErrInvalidKey = errors.New("invalid key")
|
2020-11-03 01:08:23 +03:00
|
|
|
// DefaultStore is the global default store
|
2024-03-06 18:45:32 +03:00
|
|
|
DefaultStore Store = NewStore()
|
2022-11-07 14:53:58 +03:00
|
|
|
// DefaultSeparator is the gloabal default key parts separator
|
|
|
|
DefaultSeparator = "/"
|
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 {
|
2021-01-29 13:17:32 +03:00
|
|
|
Name() string
|
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
|
2021-01-26 02:08:22 +03:00
|
|
|
Exists(ctx context.Context, key string, opts ...ExistsOption) error
|
2020-12-10 22:08:56 +03:00
|
|
|
// 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
|
|
|
}
|