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
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package channelserver
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// MiscRepository centralizes database access for miscellaneous game tables.
|
|
type MiscRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewMiscRepository creates a new MiscRepository.
|
|
func NewMiscRepository(db *dbutil.DB) *MiscRepository {
|
|
return &MiscRepository{db: db}
|
|
}
|
|
|
|
// GetTrendWeapons returns the top 3 weapon IDs for a given weapon type, ordered by count descending.
|
|
func (r *MiscRepository) GetTrendWeapons(weaponType uint8) ([]uint16, error) {
|
|
rows, err := r.db.Query("SELECT weapon_id FROM trend_weapons WHERE weapon_type=$1 ORDER BY count DESC LIMIT 3", weaponType)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("query trend_weapons: %w", err)
|
|
}
|
|
defer func() { _ = rows.Close() }()
|
|
var result []uint16
|
|
for rows.Next() {
|
|
var id uint16
|
|
if err := rows.Scan(&id); err != nil {
|
|
return nil, fmt.Errorf("scan trend_weapons: %w", err)
|
|
}
|
|
result = append(result, id)
|
|
}
|
|
return result, rows.Err()
|
|
}
|
|
|
|
// UpsertTrendWeapon increments the count for a weapon, inserting it if it doesn't exist.
|
|
func (r *MiscRepository) UpsertTrendWeapon(weaponID uint16, weaponType uint8) error {
|
|
_, err := r.db.Exec(`INSERT INTO trend_weapons (weapon_id, weapon_type, count) VALUES ($1, $2, 1) ON CONFLICT (weapon_id) DO
|
|
UPDATE SET count = trend_weapons.count+1`, weaponID, weaponType)
|
|
return err
|
|
}
|