mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 17:43:21 +01:00
refactor(channelserver): eliminate *sqlx.Rows/*sql.Rows from repository interfaces
Move scan loops from handlers into repository methods so that interfaces return typed slices instead of leaking database cursors. This fixes resource leaks (7 of 12 call sites never closed rows) and makes all 12 methods mockable for unit tests. Affected repos: CafeRepo, ShopRepo, EventRepo, RengokuRepo, DivaRepo, ScenarioRepo, MiscRepo, MercenaryRepo. New structs: DivaEvent, MercenaryLoan, GuildHuntCatUsage. EventRepo.GetEventQuests left as-is (requires broader Server refactor).
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package channelserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
@@ -15,6 +17,19 @@ func NewScenarioRepository(db *sqlx.DB) *ScenarioRepository {
|
||||
}
|
||||
|
||||
// GetCounters returns all scenario counters.
|
||||
func (r *ScenarioRepository) GetCounters() (*sqlx.Rows, error) {
|
||||
return r.db.Queryx("SELECT scenario_id, category_id FROM scenario_counter")
|
||||
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 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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user