refactor: Split monolithic sqlite.go into focused files (bd-0a43)
Split internal/storage/sqlite/sqlite.go (1050 lines) into focused files for better maintainability and code discovery: - store.go (306 lines): SQLiteStorage struct, New() constructor, initialization logic, and database utilities (Close, Path, IsClosed, UnderlyingDB, UnderlyingConn, CheckpointWAL) - queries.go (1173 lines): Issue CRUD operations including CreateIssue, GetIssue, GetIssueByExternalRef, UpdateIssue, UpdateIssueID, CloseIssue, DeleteIssue, DeleteIssues, SearchIssues with all helpers - config.go (95 lines): Configuration and metadata management (SetConfig, GetConfig, GetAllConfig, DeleteConfig, SetMetadata, GetMetadata) plus OrphanHandling type definitions - comments.go (83 lines): Comment operations (AddIssueComment, GetIssueComments) - sqlite.go (31 lines): Package documentation explaining file organization Additional changes: - Removed duplicate OrphanHandling definition from ids.go (was causing build error with new config.go) Impact: - Zero functional changes, all tests pass (2.6s runtime) - Improved code discovery: easy to locate specific functionality - Better maintainability: related code grouped logically - Reduced cognitive load: smaller, focused files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
95
internal/storage/sqlite/config.go
Normal file
95
internal/storage/sqlite/config.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// SetConfig sets a configuration value
|
||||
func (s *SQLiteStorage) SetConfig(ctx context.Context, key, value string) error {
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
INSERT INTO config (key, value) VALUES (?, ?)
|
||||
ON CONFLICT (key) DO UPDATE SET value = excluded.value
|
||||
`, key, value)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetConfig gets a configuration value
|
||||
func (s *SQLiteStorage) GetConfig(ctx context.Context, key string) (string, error) {
|
||||
var value string
|
||||
err := s.db.QueryRowContext(ctx, `SELECT value FROM config WHERE key = ?`, key).Scan(&value)
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return value, err
|
||||
}
|
||||
|
||||
// GetAllConfig gets all configuration key-value pairs
|
||||
func (s *SQLiteStorage) GetAllConfig(ctx context.Context) (map[string]string, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `SELECT key, value FROM config ORDER BY key`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = rows.Close() }()
|
||||
|
||||
config := make(map[string]string)
|
||||
for rows.Next() {
|
||||
var key, value string
|
||||
if err := rows.Scan(&key, &value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config[key] = value
|
||||
}
|
||||
return config, rows.Err()
|
||||
}
|
||||
|
||||
// DeleteConfig deletes a configuration value
|
||||
func (s *SQLiteStorage) DeleteConfig(ctx context.Context, key string) error {
|
||||
_, err := s.db.ExecContext(ctx, `DELETE FROM config WHERE key = ?`, key)
|
||||
return err
|
||||
}
|
||||
|
||||
// OrphanHandling defines how to handle orphan issues during import
|
||||
type OrphanHandling string
|
||||
|
||||
const (
|
||||
OrphanStrict OrphanHandling = "strict" // Reject imports with orphans
|
||||
OrphanResurrect OrphanHandling = "resurrect" // Auto-resurrect parents from JSONL
|
||||
OrphanSkip OrphanHandling = "skip" // Skip orphans silently
|
||||
OrphanAllow OrphanHandling = "allow" // Allow orphans (default)
|
||||
)
|
||||
|
||||
// GetOrphanHandling gets the import.orphan_handling config value
|
||||
// Returns OrphanAllow (the default) if not set or if value is invalid
|
||||
func (s *SQLiteStorage) GetOrphanHandling(ctx context.Context) OrphanHandling {
|
||||
value, err := s.GetConfig(ctx, "import.orphan_handling")
|
||||
if err != nil || value == "" {
|
||||
return OrphanAllow // Default
|
||||
}
|
||||
|
||||
switch OrphanHandling(value) {
|
||||
case OrphanStrict, OrphanResurrect, OrphanSkip, OrphanAllow:
|
||||
return OrphanHandling(value)
|
||||
default:
|
||||
return OrphanAllow // Invalid value, use default
|
||||
}
|
||||
}
|
||||
|
||||
// SetMetadata sets a metadata value (for internal state like import hashes)
|
||||
func (s *SQLiteStorage) SetMetadata(ctx context.Context, key, value string) error {
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
INSERT INTO metadata (key, value) VALUES (?, ?)
|
||||
ON CONFLICT (key) DO UPDATE SET value = excluded.value
|
||||
`, key, value)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetMetadata gets a metadata value (for internal state like import hashes)
|
||||
func (s *SQLiteStorage) GetMetadata(ctx context.Context, key string) (string, error) {
|
||||
var value string
|
||||
err := s.db.QueryRowContext(ctx, `SELECT value FROM metadata WHERE key = ?`, key).Scan(&value)
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return value, err
|
||||
}
|
||||
Reference in New Issue
Block a user