Documentation
¶
Overview ¶
Package storage provides storage backend abstractions for clarification tracking.
Index ¶
- Variables
- type BulkResult
- type ConstraintViolationError
- type DuplicateEntryError
- type ImportMode
- type ListFilter
- type NotFoundError
- type SQLiteStorage
- func (s *SQLiteStorage) Backup(ctx context.Context, path string) error
- func (s *SQLiteStorage) BulkDelete(ctx context.Context, ids []string) (*BulkResult, error)
- func (s *SQLiteStorage) BulkInsert(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
- func (s *SQLiteStorage) BulkUpdate(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) Create(ctx context.Context, entry *tracking.Entry) error
- func (s *SQLiteStorage) Delete(ctx context.Context, id string) error
- func (s *SQLiteStorage) Export(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
- func (s *SQLiteStorage) FindByQuestion(ctx context.Context, question string) (*tracking.Entry, error)
- func (s *SQLiteStorage) GetBySprint(ctx context.Context, sprint string) ([]tracking.Entry, error)
- func (s *SQLiteStorage) GetByTags(ctx context.Context, tags []string) ([]tracking.Entry, error)
- func (s *SQLiteStorage) Import(ctx context.Context, entries []tracking.Entry, mode ImportMode) (*BulkResult, error)
- func (s *SQLiteStorage) List(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
- func (s *SQLiteStorage) Read(ctx context.Context, id string) (*tracking.Entry, error)
- func (s *SQLiteStorage) Stats(ctx context.Context) (*StorageStats, error)
- func (s *SQLiteStorage) Update(ctx context.Context, entry *tracking.Entry) error
- func (s *SQLiteStorage) Vacuum(ctx context.Context) (int64, error)
- type Storage
- type StorageStats
- type StorageType
- type UnsupportedBackendError
- type YAMLStorage
- func (y *YAMLStorage) Backup(ctx context.Context, path string) error
- func (y *YAMLStorage) BulkDelete(ctx context.Context, ids []string) (*BulkResult, error)
- func (y *YAMLStorage) BulkInsert(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
- func (y *YAMLStorage) BulkUpdate(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
- func (y *YAMLStorage) Close() error
- func (y *YAMLStorage) Create(ctx context.Context, entry *tracking.Entry) error
- func (y *YAMLStorage) Delete(ctx context.Context, id string) error
- func (y *YAMLStorage) Export(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
- func (y *YAMLStorage) FindByQuestion(ctx context.Context, question string) (*tracking.Entry, error)
- func (y *YAMLStorage) GetBySprint(ctx context.Context, sprint string) ([]tracking.Entry, error)
- func (y *YAMLStorage) GetByTags(ctx context.Context, tags []string) ([]tracking.Entry, error)
- func (y *YAMLStorage) Import(ctx context.Context, entries []tracking.Entry, mode ImportMode) (*BulkResult, error)
- func (y *YAMLStorage) List(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
- func (y *YAMLStorage) Read(ctx context.Context, id string) (*tracking.Entry, error)
- func (y *YAMLStorage) Stats(ctx context.Context) (*StorageStats, error)
- func (y *YAMLStorage) Update(ctx context.Context, entry *tracking.Entry) error
- func (y *YAMLStorage) Vacuum(ctx context.Context) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound indicates the requested entry does not exist. ErrNotFound = errors.New("entry not found") // ErrDuplicateEntry indicates an entry with the same ID already exists. ErrDuplicateEntry = errors.New("duplicate entry") // ErrStorageClosed indicates an operation was attempted on a closed storage. ErrStorageClosed = errors.New("storage is closed") // ErrConstraintViolation indicates a data constraint was violated. ErrConstraintViolation = errors.New("constraint violation") // ErrUnsupportedBackend indicates the storage backend is not supported. ErrUnsupportedBackend = errors.New("unsupported storage backend") // ErrInvalidPath indicates an invalid file path was provided. ErrInvalidPath = errors.New("invalid path") // ErrConcurrentModification indicates the entry was modified by another process. ErrConcurrentModification = errors.New("concurrent modification detected") )
Sentinel errors for storage operations
Functions ¶
This section is empty.
Types ¶
type BulkResult ¶
type BulkResult struct {
// Processed is the number of entries processed.
Processed int
// Created is the number of entries created.
Created int
// Updated is the number of entries updated.
Updated int
// Skipped is the number of entries skipped.
Skipped int
// Errors contains any errors that occurred.
Errors []error
}
BulkResult contains results from a bulk operation.
type ConstraintViolationError ¶
type ConstraintViolationError struct {
Message string
}
ConstraintViolationError wraps ErrConstraintViolation with context.
func (*ConstraintViolationError) Error ¶
func (e *ConstraintViolationError) Error() string
func (*ConstraintViolationError) Unwrap ¶
func (e *ConstraintViolationError) Unwrap() error
type DuplicateEntryError ¶
type DuplicateEntryError struct {
ID string
}
DuplicateEntryError wraps ErrDuplicateEntry with context.
func (*DuplicateEntryError) Error ¶
func (e *DuplicateEntryError) Error() string
func (*DuplicateEntryError) Unwrap ¶
func (e *DuplicateEntryError) Unwrap() error
type ImportMode ¶
type ImportMode int
ImportMode specifies how entries should be imported.
const ( // ImportModeAppend adds new entries without modifying existing ones. ImportModeAppend ImportMode = iota // ImportModeOverwrite replaces all existing entries with imported ones. ImportModeOverwrite // ImportModeMerge combines entries, updating existing and adding new. ImportModeMerge )
func ParseImportMode ¶
func ParseImportMode(s string) ImportMode
ParseImportMode converts a string to ImportMode.
func (ImportMode) String ¶
func (m ImportMode) String() string
String returns the string representation of ImportMode.
type ListFilter ¶
type ListFilter struct {
// Status filters by entry status (pending, promoted, expired, rejected).
Status string
// MinOccurrences filters entries with at least this many occurrences.
MinOccurrences int
// Tags filters entries containing any of these tags.
Tags []string
// Sprint filters entries seen in this sprint.
Sprint string
// Query performs full-text search on question and answer.
Query string
// Offset for pagination (0-based).
Offset int
// Limit maximum number of results (0 = no limit).
Limit int
}
ListFilter specifies criteria for filtering entries.
type NotFoundError ¶
type NotFoundError struct {
ID string
}
NotFoundError wraps ErrNotFound with context.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage implements Storage interface using SQLite database.
func NewSQLiteStorage ¶
func NewSQLiteStorage(ctx context.Context, path string) (*SQLiteStorage, error)
NewSQLiteStorage creates a new SQLite storage instance.
func (*SQLiteStorage) Backup ¶
func (s *SQLiteStorage) Backup(ctx context.Context, path string) error
Backup creates a backup of the database.
func (*SQLiteStorage) BulkDelete ¶
func (s *SQLiteStorage) BulkDelete(ctx context.Context, ids []string) (*BulkResult, error)
BulkDelete removes multiple entries by ID.
func (*SQLiteStorage) BulkInsert ¶
func (s *SQLiteStorage) BulkInsert(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
BulkInsert adds multiple entries in a single transaction.
func (*SQLiteStorage) BulkUpdate ¶
func (s *SQLiteStorage) BulkUpdate(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
BulkUpdate modifies multiple entries in a single transaction.
func (*SQLiteStorage) Delete ¶
func (s *SQLiteStorage) Delete(ctx context.Context, id string) error
Delete removes an entry by ID.
func (*SQLiteStorage) Export ¶
func (s *SQLiteStorage) Export(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
Export returns all entries matching the filter.
func (*SQLiteStorage) FindByQuestion ¶
func (s *SQLiteStorage) FindByQuestion(ctx context.Context, question string) (*tracking.Entry, error)
FindByQuestion searches for an entry by canonical question.
func (*SQLiteStorage) GetBySprint ¶
GetBySprint returns entries seen in the specified sprint.
func (*SQLiteStorage) Import ¶
func (s *SQLiteStorage) Import(ctx context.Context, entries []tracking.Entry, mode ImportMode) (*BulkResult, error)
Import loads entries with specified mode.
func (*SQLiteStorage) List ¶
func (s *SQLiteStorage) List(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
List returns entries matching the filter criteria.
func (*SQLiteStorage) Stats ¶
func (s *SQLiteStorage) Stats(ctx context.Context) (*StorageStats, error)
Stats returns storage statistics.
type Storage ¶
type Storage interface {
// Create adds a new entry to storage.
// Returns ErrDuplicateEntry if an entry with the same ID exists.
Create(ctx context.Context, entry *tracking.Entry) error
// Read retrieves an entry by ID.
// Returns ErrNotFound if the entry does not exist.
Read(ctx context.Context, id string) (*tracking.Entry, error)
// Update modifies an existing entry.
// Returns ErrNotFound if the entry does not exist.
// Returns ErrConcurrentModification if the entry was modified since last read.
Update(ctx context.Context, entry *tracking.Entry) error
// Delete removes an entry by ID.
// Returns ErrNotFound if the entry does not exist.
Delete(ctx context.Context, id string) error
// List returns entries matching the filter criteria.
// Returns an empty slice (not nil) if no entries match.
List(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
// FindByQuestion searches for an entry by canonical question.
// Returns ErrNotFound if no matching entry exists.
FindByQuestion(ctx context.Context, question string) (*tracking.Entry, error)
// GetByTags returns entries containing any of the specified tags.
GetByTags(ctx context.Context, tags []string) ([]tracking.Entry, error)
// GetBySprint returns entries seen in the specified sprint.
GetBySprint(ctx context.Context, sprint string) ([]tracking.Entry, error)
// BulkInsert adds multiple entries in a single transaction.
// Returns a BulkResult with counts of created/updated/skipped entries.
BulkInsert(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
// BulkUpdate modifies multiple entries in a single transaction.
BulkUpdate(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
// BulkDelete removes multiple entries by ID in a single transaction.
BulkDelete(ctx context.Context, ids []string) (*BulkResult, error)
// Import loads entries with specified mode (append/overwrite/merge).
Import(ctx context.Context, entries []tracking.Entry, mode ImportMode) (*BulkResult, error)
// Export returns all entries matching the filter.
Export(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
// Vacuum performs storage optimization (e.g., SQLite VACUUM).
// Returns the number of bytes reclaimed.
Vacuum(ctx context.Context) (int64, error)
// Stats returns storage statistics.
Stats(ctx context.Context) (*StorageStats, error)
// Backup creates a backup of the storage at the specified path.
Backup(ctx context.Context, path string) error
// Close releases storage resources.
// After Close, all operations return ErrStorageClosed.
Close() error
}
Storage defines the interface for clarification entry persistence. Implementations must be safe for concurrent use from multiple goroutines.
func MustNewStorage ¶
MustNewStorage is like NewStorage but panics on error. Use only in initialization code where panicking is acceptable.
type StorageStats ¶
type StorageStats struct {
// TotalEntries is the count of all entries.
TotalEntries int
// EntriesByStatus maps status to count.
EntriesByStatus map[string]int
// TotalVariants is the count of all variant questions.
TotalVariants int
// TotalTags is the count of unique tags.
TotalTags int
// TotalSprints is the count of unique sprints.
TotalSprints int
// StorageSize is the size in bytes (for SQLite).
StorageSize int64
// LastModified is the last modification timestamp.
LastModified string
}
StorageStats provides statistics about the storage.
type StorageType ¶
type StorageType string
StorageType represents the type of storage backend.
const ( // StorageTypeYAML represents YAML file storage. StorageTypeYAML StorageType = "yaml" // StorageTypeSQLite represents SQLite database storage. StorageTypeSQLite StorageType = "sqlite" )
func DetectStorageType ¶
func DetectStorageType(path string) (StorageType, error)
DetectStorageType determines the storage type from the file path extension.
type UnsupportedBackendError ¶
type UnsupportedBackendError struct {
Extension string
}
UnsupportedBackendError wraps ErrUnsupportedBackend with context.
func (*UnsupportedBackendError) Error ¶
func (e *UnsupportedBackendError) Error() string
func (*UnsupportedBackendError) Unwrap ¶
func (e *UnsupportedBackendError) Unwrap() error
type YAMLStorage ¶
type YAMLStorage struct {
// contains filtered or unexported fields
}
YAMLStorage implements Storage interface using YAML file backend. Thread-safe via mutex for all operations.
func NewYAMLStorage ¶
func NewYAMLStorage(ctx context.Context, path string) (*YAMLStorage, error)
NewYAMLStorage creates a new YAML storage instance. Creates an empty tracking file if it doesn't exist.
func (*YAMLStorage) Backup ¶
func (y *YAMLStorage) Backup(ctx context.Context, path string) error
Backup copies the YAML file to the specified path.
func (*YAMLStorage) BulkDelete ¶
func (y *YAMLStorage) BulkDelete(ctx context.Context, ids []string) (*BulkResult, error)
BulkDelete removes multiple entries by ID.
func (*YAMLStorage) BulkInsert ¶
func (y *YAMLStorage) BulkInsert(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
BulkInsert adds multiple entries in a single operation.
func (*YAMLStorage) BulkUpdate ¶
func (y *YAMLStorage) BulkUpdate(ctx context.Context, entries []tracking.Entry) (*BulkResult, error)
BulkUpdate modifies multiple entries in a single operation.
func (*YAMLStorage) Delete ¶
func (y *YAMLStorage) Delete(ctx context.Context, id string) error
Delete removes an entry by ID.
func (*YAMLStorage) Export ¶
func (y *YAMLStorage) Export(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
Export returns all entries matching the filter.
func (*YAMLStorage) FindByQuestion ¶
FindByQuestion searches for an entry by canonical question.
func (*YAMLStorage) GetBySprint ¶
GetBySprint returns entries seen in the specified sprint.
func (*YAMLStorage) Import ¶
func (y *YAMLStorage) Import(ctx context.Context, entries []tracking.Entry, mode ImportMode) (*BulkResult, error)
Import loads entries with specified mode.
func (*YAMLStorage) List ¶
func (y *YAMLStorage) List(ctx context.Context, filter ListFilter) ([]tracking.Entry, error)
List returns entries matching the filter criteria.
func (*YAMLStorage) Stats ¶
func (y *YAMLStorage) Stats(ctx context.Context) (*StorageStats, error)
Stats returns storage statistics.