mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
Add zero-dependency SQLite mode so users can run Erupe without
PostgreSQL. A transparent db.DB wrapper auto-translates PostgreSQL
SQL ($N placeholders, now(), ::casts, ILIKE, public. prefix,
TRUNCATE) for SQLite at runtime — all 28 repo files use the wrapper
with no per-query changes needed.
Setup wizard gains two new steps: quest file detection with download
link, and gameplay presets (solo/small/community/rebalanced). The API
server gets a /dashboard endpoint with auto-refreshing stats.
CI release workflow now builds and pushes Docker images to GHCR
alongside binary artifacts on tag push.
Key changes:
- common/db: DB/Tx wrapper with 6 SQL translation rules
- server/migrations/sqlite: full SQLite schema (0001-0005)
- config: Database.Driver field ("postgres" or "sqlite")
- main.go: SQLite connection with WAL mode, single writer
- server/setup: quest check + preset selection steps
- server/api: /dashboard with live stats
- .github/workflows: Docker in release, deduplicate docker.yml
36 lines
927 B
Go
36 lines
927 B
Go
package channelserver
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// ScenarioRepository centralizes all database access for the scenario_counter table.
|
|
type ScenarioRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewScenarioRepository creates a new ScenarioRepository.
|
|
func NewScenarioRepository(db *dbutil.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()
|
|
}
|