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
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package channelserver
|
|
|
|
import (
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// DivaRepository centralizes all database access for diva defense events.
|
|
type DivaRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewDivaRepository creates a new DivaRepository.
|
|
func NewDivaRepository(db *dbutil.DB) *DivaRepository {
|
|
return &DivaRepository{db: db}
|
|
}
|
|
|
|
// DeleteEvents removes all diva events.
|
|
func (r *DivaRepository) DeleteEvents() error {
|
|
_, err := r.db.Exec("DELETE FROM events WHERE event_type='diva'")
|
|
return err
|
|
}
|
|
|
|
// InsertEvent creates a new diva event with the given start epoch.
|
|
func (r *DivaRepository) InsertEvent(startEpoch uint32) error {
|
|
_, err := r.db.Exec("INSERT INTO events (event_type, start_time) VALUES ('diva', to_timestamp($1)::timestamp without time zone)", startEpoch)
|
|
return err
|
|
}
|
|
|
|
// DivaEvent represents a diva event row with ID and start_time epoch.
|
|
type DivaEvent struct {
|
|
ID uint32 `db:"id"`
|
|
StartTime uint32 `db:"start_time"`
|
|
}
|
|
|
|
// GetEvents returns all diva events with their ID and start_time epoch.
|
|
func (r *DivaRepository) GetEvents() ([]DivaEvent, error) {
|
|
var result []DivaEvent
|
|
err := r.db.Select(&result, "SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='diva'")
|
|
return result, err
|
|
}
|