Refactor database layer to eliminate type switching and simplify architecture
- Replace type switching with clean repository pattern using sqlc-generated code - Move ContentRepository interface and domain models to db package - Create separate SQLiteRepository and PostgreSQLRepository implementations - Remove unnecessary RepositoryAdapter and ContentClient interface duplication - Update all clients (HTTP, Mock) to implement db.ContentRepository directly - Add context.Context parameters to all repository methods (Go best practice) - Eliminate duplicate domain models and type conversions - Remove type aliases - use db package types directly throughout codebase - Update engine, content managers, and API handlers to use repositories directly Benefits: - Zero runtime type switching overhead - Single source of truth for domain models - Clean package boundaries and separation of concerns - Standard Go interface patterns with context support - Easier testing with mockable repository interface - Maintainable: adding new database types requires no changes to existing code
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
)
|
||||
|
||||
var enhanceCmd = &cobra.Command{
|
||||
@@ -93,7 +92,7 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Create content client
|
||||
var client engine.ContentClient
|
||||
var client db.ContentRepository
|
||||
if cfg.API.URL != "" {
|
||||
fmt.Printf("🌐 Using content API: %s\n", cfg.API.URL)
|
||||
client = content.NewHTTPClient(cfg.API.URL, cfg.API.Key)
|
||||
@@ -104,7 +103,7 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
log.Fatalf("Failed to initialize database: %v", err)
|
||||
}
|
||||
defer database.Close()
|
||||
client = engine.NewDatabaseClient(database)
|
||||
client = database.NewContentRepository()
|
||||
} else {
|
||||
fmt.Printf("🧪 No database or API configured, using mock content\n")
|
||||
client = content.NewMockClient()
|
||||
|
||||
Reference in New Issue
Block a user