Files
Erupe/server/channelserver/repo_cafe.go
Houmgaor ecfe58ffb4 feat: add SQLite support, setup wizard enhancements, and live dashboard
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
2026-03-05 18:00:30 +01:00

66 lines
2.1 KiB
Go

package channelserver
import (
dbutil "erupe-ce/common/db"
)
// CafeRepository centralizes all database access for cafe-related tables.
type CafeRepository struct {
db *dbutil.DB
}
// NewCafeRepository creates a new CafeRepository.
func NewCafeRepository(db *dbutil.DB) *CafeRepository {
return &CafeRepository{db: db}
}
// ResetAccepted deletes all accepted cafe bonuses for a character.
func (r *CafeRepository) ResetAccepted(charID uint32) error {
_, err := r.db.Exec(`DELETE FROM cafe_accepted WHERE character_id=$1`, charID)
return err
}
// GetBonuses returns all cafe bonuses with their claimed status for a character.
func (r *CafeRepository) GetBonuses(charID uint32) ([]CafeBonus, error) {
var result []CafeBonus
err := r.db.Select(&result, `
SELECT cb.id, time_req, item_type, item_id, quantity,
(
SELECT count(*)
FROM cafe_accepted ca
WHERE cb.id = ca.cafe_id AND ca.character_id = $1
)::int::bool AS claimed
FROM cafebonus cb ORDER BY id ASC;`, charID)
return result, err
}
// GetClaimable returns unclaimed cafe bonuses where the character has enough accumulated time.
func (r *CafeRepository) GetClaimable(charID uint32, elapsedSec int64) ([]CafeBonus, error) {
var result []CafeBonus
err := r.db.Select(&result, `
SELECT c.id, time_req, item_type, item_id, quantity
FROM cafebonus c
WHERE (
SELECT count(*)
FROM cafe_accepted ca
WHERE c.id = ca.cafe_id AND ca.character_id = $1
) < 1 AND (
SELECT ch.cafe_time + $2
FROM characters ch
WHERE ch.id = $1
) >= time_req`, charID, elapsedSec)
return result, err
}
// GetBonusItem returns the item type and quantity for a specific cafe bonus.
func (r *CafeRepository) GetBonusItem(bonusID uint32) (itemType, quantity uint32, err error) {
err = r.db.QueryRow(`SELECT cb.id, item_type, quantity FROM cafebonus cb WHERE cb.id=$1`, bonusID).Scan(&bonusID, &itemType, &quantity)
return
}
// AcceptBonus records that a character has accepted a cafe bonus.
func (r *CafeRepository) AcceptBonus(bonusID, charID uint32) error {
_, err := r.db.Exec("INSERT INTO cafe_accepted VALUES ($1, $2)", bonusID, charID)
return err
}