2020-03-12 16:41:30 +03:00
|
|
|
// Package store is an interface for distributed data storage.
|
2023-04-11 22:20:37 +03:00
|
|
|
package store // import "go.unistack.org/micro/v4/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"
|
2023-07-29 00:40:58 +03:00
|
|
|
|
|
|
|
"go.unistack.org/micro/v4/options"
|
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")
|
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
|
2022-05-03 14:38:44 +03:00
|
|
|
DefaultStore = 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
|
2023-07-29 00:40:58 +03:00
|
|
|
Init(opts ...options.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
|
2023-07-29 00:40:58 +03:00
|
|
|
Exists(ctx context.Context, key string, opts ...options.Option) error
|
|
|
|
// Read reads a single key name to provided value with optional options
|
|
|
|
Read(ctx context.Context, key string, val interface{}, opts ...options.Option) error
|
|
|
|
// Write writes a value to key name to the store with optional options
|
|
|
|
Write(ctx context.Context, key string, val interface{}, opts ...options.Option) error
|
|
|
|
// Delete removes the record with the corresponding key from the store with optional options
|
|
|
|
Delete(ctx context.Context, key string, opts ...options.Option) error
|
|
|
|
// List returns any keys that match, or an empty list with no error if none matched with optional options
|
|
|
|
List(ctx context.Context, opts ...options.Option) ([]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
|
|
|
}
|