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

@@ -105,6 +105,18 @@ func (db *Database) GetPostgreSQLDB() *sql.DB {
return db.conn
}
// NewContentRepository creates a repository based on the database type
func (db *Database) NewContentRepository() ContentRepository {
switch db.dbType {
case "sqlite3":
return NewSQLiteRepository(db.conn)
case "postgresql":
return NewPostgreSQLRepository(db.conn)
default:
panic(fmt.Sprintf("unsupported database type: %s", db.dbType))
}
}
// initializeSQLiteSchema sets up the SQLite database schema
func (db *Database) initializeSQLiteSchema() error {
ctx := context.Background()