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:
2025-10-08 19:34:21 +02:00
parent 38c2897ece
commit 01b921bfa3
16 changed files with 785 additions and 712 deletions

View File

@@ -1,7 +1,6 @@
package engine
import (
"database/sql"
"strings"
"golang.org/x/net/html"
@@ -38,7 +37,6 @@ func getAttribute(node *html.Node, key string) string {
return ""
}
// hasOnlyTextContent checks if a node contains only text content (no nested HTML elements)
// DEPRECATED: Use hasEditableContent for more sophisticated detection
func hasOnlyTextContent(node *html.Node) bool {
@@ -303,7 +301,6 @@ func hasInsertrClass(node *html.Node) bool {
return false
}
// isSelfClosing checks if an element is typically self-closing
func isSelfClosing(node *html.Node) bool {
if node.Type != html.ElementNode {
@@ -376,24 +373,6 @@ func FindViableChildren(node *html.Node) []*html.Node {
return findViableChildren(node)
}
// SQL utility functions for consistent null string handling
// ToNullString converts a string to sql.NullString
func ToNullString(s string) sql.NullString {
if s == "" {
return sql.NullString{Valid: false}
}
return sql.NullString{String: s, Valid: true}
}
// FromNullString converts sql.NullString to string
func FromNullString(ns sql.NullString) string {
if ns.Valid {
return ns.String
}
return ""
}
// Text extraction utility functions
// ExtractTextContent extracts all text content from an HTML node recursively