storage

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when an entity is not found
	ErrNotFound = errors.New("entity not found")
	// ErrAlreadyExists is returned when an entity already exists
	ErrAlreadyExists = errors.New("entity already exists")
	// ErrInvalidEntity is returned when entity name is invalid
	ErrInvalidEntity = errors.New("invalid entity name")
	// ErrInvalidID is returned when ID is invalid
	ErrInvalidID = errors.New("invalid ID")
)

Functions

func ListStores

func ListStores() []string

ListStores returns all registered store types

func RegisterStore

func RegisterStore(name string, factory StoreFactory)

RegisterStore registers a new store implementation

func WithTransaction

func WithTransaction(ctx context.Context, store Store, fn func(Transaction) error) error

WithTransaction executes a function within a transaction if the store supports it

Types

type Batcher

type Batcher interface {
	BatchCreate(ctx context.Context, entity string, items []map[string]interface{}) ([]int, error)
	BatchDelete(ctx context.Context, entity string, ids []int) error
}

Batcher defines optional batch operation support

type GraphIntegrity

type GraphIntegrity interface {
	VerifyGraphIntegrity(ctx context.Context) error
	RebuildGraph(ctx context.Context) error
}

GraphIntegrity defines optional graph integrity checking

type GraphNeighbors

type GraphNeighbors interface {
	GetNeighbors(ctx context.Context, entity string, id int, direction string) ([]map[string]interface{}, error)
}

GraphNeighbors defines optional graph neighbor queries

type IDGenerator

type IDGenerator interface {
	NextID(ctx context.Context, entity string) (int, error)
}

IDGenerator defines interface for ID generation strategies

type InfoProvider

type InfoProvider interface {
	Info() StoreInfo
}

InfoProvider allows stores to provide metadata about their capabilities

type JSONFileStore

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

JSONFileStore implements Store interface using JSON files

func NewJSONFileStore

func NewJSONFileStore(baseDir, schema string) (*JSONFileStore, error)

NewJSONFileStore creates a new JSON file-based storage

func (*JSONFileStore) Close

func (s *JSONFileStore) Close() error

Close closes the storage (cleanup if needed)

func (*JSONFileStore) Create

func (s *JSONFileStore) Create(ctx context.Context, entity string, data map[string]interface{}) (int, error)

Create creates a new entity with auto-generated ID

func (*JSONFileStore) Delete

func (s *JSONFileStore) Delete(ctx context.Context, entity string, id int) error

Delete removes an entity

func (*JSONFileStore) Exists

func (s *JSONFileStore) Exists(ctx context.Context, entity string, id int) bool

Exists checks if an entity exists

func (*JSONFileStore) FullTextSearch

func (s *JSONFileStore) FullTextSearch(ctx context.Context, query string, entity string) ([]map[string]interface{}, error)

FullTextSearch is not supported for JSONFileStore, returns empty results

func (*JSONFileStore) Get

func (s *JSONFileStore) Get(ctx context.Context, entity string, id int) (map[string]interface{}, error)

Get retrieves an entity by ID

func (*JSONFileStore) GetEntityDir

func (s *JSONFileStore) GetEntityDir(entity string) string

GetEntityDir returns the directory path for an entity

func (*JSONFileStore) Info

func (s *JSONFileStore) Info() StoreInfo

Info returns store information

func (*JSONFileStore) List

func (s *JSONFileStore) List(ctx context.Context, entity string) ([]map[string]interface{}, error)

List returns all entities of a given type

func (*JSONFileStore) ListEntities

func (s *JSONFileStore) ListEntities(ctx context.Context) ([]string, error)

ListEntities returns all entity types in the schema

func (*JSONFileStore) NextID

func (s *JSONFileStore) NextID(ctx context.Context, entity string) (int, error)

NextID gets the next available ID for an entity

func (*JSONFileStore) Patch

func (s *JSONFileStore) Patch(ctx context.Context, entity string, id int, patchData map[string]interface{}) error

Patch partially updates an entity

func (*JSONFileStore) Save

func (s *JSONFileStore) Save(ctx context.Context, entity string, id int, data map[string]interface{}) error

Save saves an entity with a specific ID (creates if doesn't exist)

func (*JSONFileStore) Search

func (s *JSONFileStore) Search(ctx context.Context, entity string, field string, query string, matchType string) ([]map[string]interface{}, error)

Search implements field-based search

func (*JSONFileStore) Update

func (s *JSONFileStore) Update(ctx context.Context, entity string, id int, data map[string]interface{}) error

Update replaces an entity completely

type Migrator

type Migrator interface {
	Migrate(ctx context.Context) error
	Version(ctx context.Context) (int, error)
}

Migrator defines optional schema migration support Useful for database backends

type SQLiteConfig

type SQLiteConfig struct {
	DBPath            string
	EnableWAL         bool // Write-Ahead Logging for better concurrency
	EnableForeignKeys bool
	CacheSize         int  // Page cache size in KB
	BusyTimeout       int  // Milliseconds to wait on locked database
	FullTextEnabled   bool // Enable FTS5 full-text search indexing
}

SQLiteConfig holds SQLite-specific configuration

type SQLiteStore

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

SQLiteStore implements Store interface using SQLite database

func NewSQLiteStore

func NewSQLiteStore(dbPath string, config SQLiteConfig) (*SQLiteStore, error)

NewSQLiteStore creates a new SQLite-based storage

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connection

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, entity string, data map[string]interface{}) (int, error)

Create inserts a new entity with auto-generated ID

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, entity string, id int) error

Delete removes an entity

func (*SQLiteStore) Exists

func (s *SQLiteStore) Exists(ctx context.Context, entity string, id int) bool

Exists checks if an entity exists

func (*SQLiteStore) FullTextSearch

func (s *SQLiteStore) FullTextSearch(ctx context.Context, query string, entity string) ([]map[string]interface{}, error)

FullTextSearch performs a full-text search across entities

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, entity string, id int) (map[string]interface{}, error)

Get retrieves an entity by ID

func (*SQLiteStore) GetNeighbors

func (s *SQLiteStore) GetNeighbors(ctx context.Context, entity string, id int, direction string) ([]map[string]interface{}, error)

GetNeighbors returns graph neighbors for an entity

func (*SQLiteStore) Info

func (s *SQLiteStore) Info() StoreInfo

Info returns store information

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, entity string) ([]map[string]interface{}, error)

List returns all entities of a given type

func (*SQLiteStore) Patch

func (s *SQLiteStore) Patch(ctx context.Context, entity string, id int, updates map[string]interface{}) error

Patch partially updates an entity

func (*SQLiteStore) RebuildGraph

func (s *SQLiteStore) RebuildGraph(ctx context.Context) error

RebuildGraph rebuilds the graph_edges table from JSON data

func (*SQLiteStore) Save

func (s *SQLiteStore) Save(ctx context.Context, entity string, id int, data map[string]interface{}) error

Save creates an entity with a specific ID (fails if exists)

func (*SQLiteStore) Search

func (s *SQLiteStore) Search(ctx context.Context, entity string, field string, query string, matchType string) ([]map[string]interface{}, error)

Search implements field-based search using JSON extraction

func (*SQLiteStore) Update

func (s *SQLiteStore) Update(ctx context.Context, entity string, id int, data map[string]interface{}) error

Update replaces an entity completely

func (*SQLiteStore) VerifyGraphIntegrity

func (s *SQLiteStore) VerifyGraphIntegrity(ctx context.Context) error

VerifyGraphIntegrity checks if graph_edges matches JSON REF fields

type Searcher

type Searcher interface {
	Search(ctx context.Context, entity string, field string, query string, matchType string) ([]map[string]interface{}, error)
}

Searcher defines optional search capabilities

type Store

type Store interface {
	// Entity CRUD operations
	Create(ctx context.Context, entity string, data map[string]interface{}) (int, error)
	Get(ctx context.Context, entity string, id int) (map[string]interface{}, error)
	Update(ctx context.Context, entity string, id int, data map[string]interface{}) error
	Patch(ctx context.Context, entity string, id int, data map[string]interface{}) error
	Delete(ctx context.Context, entity string, id int) error
	Save(ctx context.Context, entity string, id int, data map[string]interface{}) error

	// Query operations
	List(ctx context.Context, entity string) ([]map[string]interface{}, error)
	Exists(ctx context.Context, entity string, id int) bool
	Search(ctx context.Context, entity string, field string, query string, matchType string) ([]map[string]interface{}, error)

	// Full-text search (optional - may return empty if not supported)
	FullTextSearch(ctx context.Context, query string, entity string) ([]map[string]interface{}, error)

	// Lifecycle
	Close() error
}

Store defines the core interface for entity storage backends

func NewStore

func NewStore(name string, config map[string]interface{}) (Store, error)

NewStore creates a new store instance by name

type StoreFactory

type StoreFactory func(config map[string]interface{}) (Store, error)

StoreFactory is a function that creates a new Store instance

type StoreInfo

type StoreInfo struct {
	Type                string // "jsonfile", "sqlite", "postgres", etc.
	Version             string
	SupportsSearch      bool
	SupportsBatch       bool
	SupportsTransaction bool
}

StoreInfo provides metadata about the store implementation

type Transaction

type Transaction interface {
	Store
	Commit() error
	Rollback() error
}

Transaction represents a storage transaction

type Transactional

type Transactional interface {
	Store
	Begin(ctx context.Context) (Transaction, error)
}

Transactional defines optional transaction support Stores that support transactions should implement this interface

Jump to

Keyboard shortcuts

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