storage

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Filesystem-backed key-value storage.

In-memory key-value storage for tests and temporary use.

SQLite key-value storage using the pure-Go liustack/sqlite driver.

Package storage provides Storage Domain KV abstractions, matching core/storage-domain. Backend supplies versioned Get/Put/Delete/List with file, SQLite, and memory implementations. Domain[T] serializes typed values and exposes consistent CAS semantics: writes supply an expected version and conflicts return ErrCASMismatch. Feedback, goal views, session sidecars, skill catalogs, and workspace registries share this typed persistence layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCASMismatch

func IsCASMismatch(err error) bool

IsCASMismatch identifies CAS version conflicts.

func IsKeyNotFound

func IsKeyNotFound(err error) bool

IsKeyNotFound identifies missing-key errors.

func Migrate

func Migrate(ctx context.Context, src, dst Backend) (migrated int, skipped []string, err error)

Migrate copies source keys to a destination backend. Conflicting destination keys with newer versions are skipped and recorded.

Types

type Backend

type Backend interface {
	// Get returns data and version, or ErrKeyNotFound.
	Get(ctx context.Context, key string) (data []byte, version uint64, err error)
	// Put writes with CAS; expectedVersion=0 requests creation.
	Put(ctx context.Context, key string, data []byte, expectedVersion uint64) (version uint64, err error)
	// Delete removes a key; missing keys are not errors.
	Delete(ctx context.Context, key string) error
	// List returns keys beneath a prefix with that prefix removed.
	List(ctx context.Context, prefix string) (keys []string, err error)
}

Backend provides versioned key-value storage. Creation expects version zero and produces version one. Other Put calls must match the current version or return *ErrCASMismatch.

type Domain

type Domain[T any] struct {
	// contains filtered or unexported fields
}

Domain provides typed storage with a common prefix to prevent cross-domain collisions.

func NewDomain

func NewDomain[T any](backend Backend, prefix string) *Domain[T]

NewDomain uses a prefix such as feedback/ to isolate a domain.

func (*Domain[T]) Delete

func (d *Domain[T]) Delete(ctx context.Context, key string) error

Delete removes a domain value.

func (*Domain[T]) Get

func (d *Domain[T]) Get(ctx context.Context, key string) (T, uint64, error)

Get reads and decodes a value, returning its current version.

func (*Domain[T]) List

func (d *Domain[T]) List(ctx context.Context) ([]string, error)

List returns domain-relative keys.

func (*Domain[T]) Put

func (d *Domain[T]) Put(ctx context.Context, key string, value T, expectedVersion uint64) (uint64, error)

Put serializes and CAS-writes a value using the version from Get; zero creates it.

type ErrCASMismatch

type ErrCASMismatch struct {
	Key             string
	ExpectedVersion uint64
	ActualVersion   uint64
}

ErrCASMismatch indicates that an expected write version differs from the stored version.

func (*ErrCASMismatch) Error

func (e *ErrCASMismatch) Error() string

Error implements error.

type ErrKeyNotFound

type ErrKeyNotFound struct {
	Key string
}

ErrKeyNotFound indicates a missing key.

func (*ErrKeyNotFound) Error

func (e *ErrKeyNotFound) Error() string

Error implements error.

type FileKV

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

FileKV implements Backend with files at <root>/<key> containing {"version":N,"data":"<base64>"}.

func NewFileKV

func NewFileKV(root string) (*FileKV, error)

NewFileKV creates a file backend and its root directory if needed.

func (*FileKV) Delete

func (f *FileKV) Delete(ctx context.Context, key string) error

Delete implements Backend.

func (*FileKV) Get

func (f *FileKV) Get(ctx context.Context, key string) ([]byte, uint64, error)

Get implements Backend.

func (*FileKV) List

func (f *FileKV) List(ctx context.Context, prefix string) ([]string, error)

List returns keys under the root as relative paths, preserving key separators.

func (*FileKV) Put

func (f *FileKV) Put(ctx context.Context, key string, data []byte, expectedVersion uint64) (uint64, error)

Put implements Backend with CAS.

type MemoryKV

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

MemoryKV implements Backend with an in-memory map.

func NewMemoryKV

func NewMemoryKV() *MemoryKV

NewMemoryKV creates an empty in-memory backend.

func (*MemoryKV) Delete

func (m *MemoryKV) Delete(ctx context.Context, key string) error

Delete implements Backend.

func (*MemoryKV) Get

func (m *MemoryKV) Get(ctx context.Context, key string) ([]byte, uint64, error)

Get implements Backend.

func (*MemoryKV) List

func (m *MemoryKV) List(ctx context.Context, prefix string) ([]string, error)

List implements Backend with deterministic lexical ordering.

func (*MemoryKV) Put

func (m *MemoryKV) Put(ctx context.Context, key string, data []byte, expectedVersion uint64) (uint64, error)

Put implements Backend with CAS.

type SQLiteKV

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

SQLiteKV implements Backend using kv(key TEXT PRIMARY KEY, version INTEGER, data BLOB).

func NewSQLiteKV

func NewSQLiteKV(path string) (*SQLiteKV, error)

NewSQLiteKV opens or creates a database and initializes its table.

func (*SQLiteKV) Close

func (s *SQLiteKV) Close() error

Close closes the underlying database connection.

func (*SQLiteKV) Delete

func (s *SQLiteKV) Delete(ctx context.Context, key string) error

Delete implements Backend.

func (*SQLiteKV) Get

func (s *SQLiteKV) Get(ctx context.Context, key string) ([]byte, uint64, error)

Get implements Backend.

func (*SQLiteKV) List

func (s *SQLiteKV) List(ctx context.Context, prefix string) ([]string, error)

List implements Backend.

func (*SQLiteKV) Put

func (s *SQLiteKV) Put(ctx context.Context, key string, data []byte, expectedVersion uint64) (uint64, error)

Put implements CAS, detecting conflicts from affected UPDATE rows.

Jump to

Keyboard shortcuts

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