kvstore

package
v0.0.0-kmdagger3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Wildcard to query all organizations
	AllOrganizations = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeKVStore

type FakeKVStore struct {
	// contains filtered or unexported fields
}

In memory kv store used for testing

func NewFakeKVStore

func NewFakeKVStore() *FakeKVStore

func (*FakeKVStore) Del

func (f *FakeKVStore) Del(ctx context.Context, orgId int64, namespace string, key string) error

func (*FakeKVStore) DeletionError

func (f *FakeKVStore) DeletionError(shouldErr bool)

func (*FakeKVStore) Get

func (f *FakeKVStore) Get(ctx context.Context, orgId int64, namespace string, key string) (string, bool, error)

func (*FakeKVStore) GetAll

func (f *FakeKVStore) GetAll(ctx context.Context, orgId int64, namespace string) (map[int64]map[string]string, error)

func (*FakeKVStore) Keys

func (f *FakeKVStore) Keys(ctx context.Context, orgId int64, namespace string, keyPrefix string) ([]Key, error)

List all keys with an optional filter. If default values are provided, filter is not applied.

func (*FakeKVStore) Set

func (f *FakeKVStore) Set(ctx context.Context, orgId int64, namespace string, key string, value string) error

type Item

type Item struct {
	Id        int64
	OrgId     *int64
	Namespace *string
	Key       *string
	Value     string

	Created time.Time
	Updated time.Time
}

Item stored in k/v store.

func (*Item) TableName

func (i *Item) TableName() string

type KVStore

type KVStore interface {
	Get(ctx context.Context, orgId int64, namespace string, key string) (string, bool, error)
	Set(ctx context.Context, orgId int64, namespace string, key string, value string) error
	Del(ctx context.Context, orgId int64, namespace string, key string) error
	Keys(ctx context.Context, orgId int64, namespace string, keyPrefix string) ([]Key, error)
	GetAll(ctx context.Context, orgId int64, namespace string) (map[int64]map[string]string, error)
}

KVStore is an interface for k/v store.

func ProvideService

func ProvideService(sqlStore db.DB) KVStore

type Key

type Key struct {
	OrgId     int64
	Namespace string
	Key       string
}

func (*Key) TableName

func (i *Key) TableName() string

type NamespacedKVStore

type NamespacedKVStore struct {
	// contains filtered or unexported fields
}

NamespacedKVStore is a KVStore wrapper with fixed orgId and namespace.

func WithNamespace

func WithNamespace(kv KVStore, orgId int64, namespace string) *NamespacedKVStore

WithNamespace returns a kvstore wrapper with fixed orgId and namespace.

func (*NamespacedKVStore) Del

func (kv *NamespacedKVStore) Del(ctx context.Context, key string) error

func (*NamespacedKVStore) Get

func (kv *NamespacedKVStore) Get(ctx context.Context, key string) (string, bool, error)

func (*NamespacedKVStore) GetAll

func (kv *NamespacedKVStore) GetAll(ctx context.Context) (map[int64]map[string]string, error)

GetAll returns all the keys and values stored per organization. It returns a map of org -> key -> value.

func (*NamespacedKVStore) Keys

func (kv *NamespacedKVStore) Keys(ctx context.Context, keyPrefix string) ([]Key, error)

func (*NamespacedKVStore) Set

func (kv *NamespacedKVStore) Set(ctx context.Context, key string, value string) error

Jump to

Keyboard shortcuts

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