Help us shape the future of Go! Take the 2026 Go Developer Survey

kvs

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package kvs provides a key-value storage interface.

Storage backends are used for:

  • Session state and conversation history
  • Caching expensive operations
  • User preferences and settings

Available Backends

  • memory: In-memory storage (default, no persistence)
  • sqlite: SQLite database (recommended for persistent storage)
  • dynamodb: AWS DynamoDB (for serverless deployments)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("key not found")
	ErrClosed   = errors.New("storage is closed")
)

Common errors.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Type is the storage backend type: "memory", "sqlite", "dynamodb".
	Type string `yaml:"type" json:"type"`

	// Path is the database path (for sqlite).
	Path string `yaml:"path,omitempty" json:"path,omitempty"`

	// TableName is the table name (for dynamodb).
	TableName string `yaml:"table_name,omitempty" json:"table_name,omitempty"`

	// Region is the AWS region (for dynamodb).
	Region string `yaml:"region,omitempty" json:"region,omitempty"`
}

Config configures storage creation.

type Document

type Document struct {
	// ID is the document identifier.
	ID string

	// Data contains the document fields.
	Data map[string]any

	// Metadata contains system metadata.
	Metadata map[string]string

	// CreatedAt is when the document was created.
	CreatedAt time.Time

	// UpdatedAt is when the document was last modified.
	UpdatedAt time.Time
}

Document represents a stored document.

type DocumentStore

type DocumentStore interface {
	Store

	// Put stores a document in a collection.
	Put(ctx context.Context, collection string, doc Document) error

	// Query retrieves documents matching a filter.
	Query(ctx context.Context, collection string, filter map[string]any) ([]Document, error)

	// DeleteDoc removes a document by ID.
	DeleteDoc(ctx context.Context, collection, id string) error
}

DocumentStore extends Store with document operations.

type ListableStore

type ListableStore interface {
	Store

	// List returns all keys matching the given prefix.
	// If prefix is empty, returns all keys.
	List(ctx context.Context, prefix string) ([]string, error)
}

ListableStore extends Store with key listing.

type Store

type Store interface {
	// Get retrieves a value by key.
	// Returns ErrNotFound if the key doesn't exist or has expired.
	Get(ctx context.Context, key string) ([]byte, error)

	// Set stores a value with an optional TTL.
	// If ttl is 0, the value never expires.
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

	// Delete removes a key.
	// Returns nil if the key doesn't exist.
	Delete(ctx context.Context, key string) error

	// Close releases storage resources.
	Close() error
}

Store is the primary key-value storage interface.

Directories

Path Synopsis
backend
memory
Package memory provides an in-memory key-value storage backend.
Package memory provides an in-memory key-value storage backend.
redis
Package redis provides a Redis-backed key-value storage backend.
Package redis provides a Redis-backed key-value storage backend.
sqlite
Package sqlite provides a SQLite key-value storage backend.
Package sqlite provides a SQLite key-value storage backend.

Jump to

Keyboard shortcuts

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