Documentation
¶
Index ¶
- Variables
- func ListStores() []string
- func RegisterStore(name string, factory StoreFactory)
- func WithTransaction(ctx context.Context, store Store, fn func(Transaction) error) error
- type Batcher
- type GraphIntegrity
- type GraphNeighbors
- type IDGenerator
- type InfoProvider
- type JSONFileStore
- func (s *JSONFileStore) Close() error
- func (s *JSONFileStore) Create(ctx context.Context, entity string, data map[string]interface{}) (int, error)
- func (s *JSONFileStore) Delete(ctx context.Context, entity string, id int) error
- func (s *JSONFileStore) Exists(ctx context.Context, entity string, id int) bool
- func (s *JSONFileStore) FullTextSearch(ctx context.Context, query string, entity string) ([]map[string]interface{}, error)
- func (s *JSONFileStore) Get(ctx context.Context, entity string, id int) (map[string]interface{}, error)
- func (s *JSONFileStore) GetEntityDir(entity string) string
- func (s *JSONFileStore) Info() StoreInfo
- func (s *JSONFileStore) List(ctx context.Context, entity string) ([]map[string]interface{}, error)
- func (s *JSONFileStore) ListEntities(ctx context.Context) ([]string, error)
- func (s *JSONFileStore) NextID(ctx context.Context, entity string) (int, error)
- func (s *JSONFileStore) Patch(ctx context.Context, entity string, id int, patchData map[string]interface{}) error
- func (s *JSONFileStore) Save(ctx context.Context, entity string, id int, data map[string]interface{}) error
- func (s *JSONFileStore) Search(ctx context.Context, entity string, field string, query string, ...) ([]map[string]interface{}, error)
- func (s *JSONFileStore) Update(ctx context.Context, entity string, id int, data map[string]interface{}) error
- type Migrator
- type SQLiteConfig
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Create(ctx context.Context, entity string, data map[string]interface{}) (int, error)
- func (s *SQLiteStore) Delete(ctx context.Context, entity string, id int) error
- func (s *SQLiteStore) Exists(ctx context.Context, entity string, id int) bool
- func (s *SQLiteStore) FullTextSearch(ctx context.Context, query string, entity string) ([]map[string]interface{}, error)
- func (s *SQLiteStore) Get(ctx context.Context, entity string, id int) (map[string]interface{}, error)
- func (s *SQLiteStore) GetNeighbors(ctx context.Context, entity string, id int, direction string) ([]map[string]interface{}, error)
- func (s *SQLiteStore) Info() StoreInfo
- func (s *SQLiteStore) List(ctx context.Context, entity string) ([]map[string]interface{}, error)
- func (s *SQLiteStore) Patch(ctx context.Context, entity string, id int, updates map[string]interface{}) error
- func (s *SQLiteStore) RebuildGraph(ctx context.Context) error
- func (s *SQLiteStore) Save(ctx context.Context, entity string, id int, data map[string]interface{}) error
- func (s *SQLiteStore) Search(ctx context.Context, entity string, field string, query string, ...) ([]map[string]interface{}, error)
- func (s *SQLiteStore) Update(ctx context.Context, entity string, id int, data map[string]interface{}) error
- func (s *SQLiteStore) VerifyGraphIntegrity(ctx context.Context) error
- type Searcher
- type Store
- type StoreFactory
- type StoreInfo
- type Transaction
- type Transactional
Constants ¶
This section is empty.
Variables ¶
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 RegisterStore ¶
func RegisterStore(name string, factory StoreFactory)
RegisterStore registers a new store implementation
func WithTransaction ¶
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 ¶
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) 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) ListEntities ¶
func (s *JSONFileStore) ListEntities(ctx context.Context) ([]string, error)
ListEntities returns all entity types in the schema
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)
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) 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) 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
type StoreFactory ¶
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 ¶
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