configstore

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreAlreadyRegistered = errors.New("config store schema already registered")
	ErrUnknownStoreName       = errors.New("unknown config store")
)
View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by store implementations when a requested record does not exist. Gateway layers should check for this error rather than depending on storage-specific errors (e.g. gorm.ErrRecordNotFound).

Functions

func RegisterConfigStoreCreatorFactory

func RegisterConfigStoreCreatorFactory(name string, factory ConfigStoreCreatorFactory)

Types

type Backend

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

Backend contains the generic schema registration and store lookup logic shared by persisted config store backends.

func NewBackend

func NewBackend(creator ConfigStoreCreator) *Backend

func (*Backend) Get

func (b *Backend) Get(name string) (ConfigStore, error)

func (*Backend) Register

func (b *Backend) Register(name string, storeSchema StoreSchema) error

type ConfigObjectCodec

type ConfigObjectCodec interface {
	Encode(obj any) ([]byte, error)
	Decode(data []byte) (any, error)
}

ConfigObjectCodec owns serialization and deserialization for one object family.

type ConfigStore

type ConfigStore interface {
	List(ctx context.Context) ([]any, error)
	ListByTag(ctx context.Context, tag string) ([]any, error)
	ListByTagPrefix(ctx context.Context, tagPrefix string) ([]any, error)

	Create(ctx context.Context, obj any) error
	Update(ctx context.Context, obj any) error
	Delete(ctx context.Context, keyParts ...any) error

	Get(ctx context.Context, keyParts ...any) (any, error)
	GetByIndex(ctx context.Context, indexName string, value any) (any, error)
}

ConfigStore is a schema-bound generic store for one persisted object family.

type ConfigStoreBackend

type ConfigStoreBackend interface {
	Register(name string, storeSchema StoreSchema) error
	Get(name string) (ConfigStore, error)
}

ConfigStoreBackend registers store schemas and returns schema-bound stores.

func OpenBackend

func OpenBackend(ctx context.Context, name string, cfg any, logger *zap.Logger) (ConfigStoreBackend, error)

func OpenBackendJSON

func OpenBackendJSON(ctx context.Context, name string, raw json.RawMessage, logger *zap.Logger) (ConfigStoreBackend, error)

type ConfigStoreCreator

type ConfigStoreCreator interface {
	NewStore(storeSchema StoreSchema) (ConfigStore, error)
}

type ConfigStoreCreatorFactory

type ConfigStoreCreatorFactory func(context.Context, json.RawMessage, *zap.Logger) (ConfigStoreCreator, error)

type IndexSchema

type IndexSchema struct {
	Name   string
	Column string
	Unique bool
}

type MetadataFuncs

type MetadataFuncs struct {
	PrimaryKeyFunc func(obj any) ([]any, error)
	TagFunc        func(obj any) (string, bool, error)
	IndexesFunc    func(obj any) (map[string]any, error)
}

MetadataFuncs adapts functions to ObjectMetadata.

func (MetadataFuncs) Indexes

func (m MetadataFuncs) Indexes(obj any) (map[string]any, error)

func (MetadataFuncs) PrimaryKey

func (m MetadataFuncs) PrimaryKey(obj any) ([]any, error)

func (MetadataFuncs) Tag

func (m MetadataFuncs) Tag(obj any) (string, bool, error)

type ObjectMetadata

type ObjectMetadata interface {
	PrimaryKey(obj any) ([]any, error)
	Tag(obj any) (string, bool, error)
	Indexes(obj any) (map[string]any, error)
}

ObjectMetadata extracts storage metadata from one persisted object family.

type ObjectUnwrapper

type ObjectUnwrapper interface {
	ConfigStoreObject() any
}

ObjectUnwrapper exposes the underlying persisted object when an adapter needs to attach extra metadata without changing the stored payload shape.

type StoreSchema

type StoreSchema struct {
	Name  string
	Kind  string
	Table string

	PrimaryKeyColumns []string
	TagColumn         string
	DataColumn        string

	IndexColumns []IndexSchema
	Timestamped  bool

	Codec    ConfigObjectCodec
	Metadata ObjectMetadata
}

StoreSchema describes how one object family is persisted.

type TagCarrier

type TagCarrier interface {
	ConfigStoreTag() string
}

TagCarrier carries a tag value outside the persisted object payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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