mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
Fix errcheck violations across 11 repo files by wrapping deferred rows.Close() and tx.Rollback() calls to discard the error return. Fix unchecked Scan/Exec calls in guild store tests. Fix staticcheck SA9003 empty branch in test helpers. Add 6 mock-based unit tests for GetCharacterSaveData covering nil savedata, sql.ErrNoRows, DB errors, compressed round-trip, new-character skip, and config mode/pointer propagation.
36 lines
921 B
Go
36 lines
921 B
Go
package channelserver
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
// ScenarioRepository centralizes all database access for the scenario_counter table.
|
|
type ScenarioRepository struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
// NewScenarioRepository creates a new ScenarioRepository.
|
|
func NewScenarioRepository(db *sqlx.DB) *ScenarioRepository {
|
|
return &ScenarioRepository{db: db}
|
|
}
|
|
|
|
// GetCounters returns all scenario counters.
|
|
func (r *ScenarioRepository) GetCounters() ([]Scenario, error) {
|
|
rows, err := r.db.Query("SELECT scenario_id, category_id FROM scenario_counter")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("query scenario_counter: %w", err)
|
|
}
|
|
defer func() { _ = rows.Close() }()
|
|
var result []Scenario
|
|
for rows.Next() {
|
|
var s Scenario
|
|
if err := rows.Scan(&s.MainID, &s.CategoryID); err != nil {
|
|
return nil, fmt.Errorf("scan scenario_counter: %w", err)
|
|
}
|
|
result = append(result, s)
|
|
}
|
|
return result, rows.Err()
|
|
}
|