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
48 lines
1.9 KiB
Go
48 lines
1.9 KiB
Go
package channelserver
|
|
|
|
import (
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// ShopRepository centralizes all database access for shop-related tables.
|
|
type ShopRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewShopRepository creates a new ShopRepository.
|
|
func NewShopRepository(db *dbutil.DB) *ShopRepository {
|
|
return &ShopRepository{db: db}
|
|
}
|
|
|
|
// GetShopItems returns shop items with per-character purchase counts.
|
|
func (r *ShopRepository) GetShopItems(shopType uint8, shopID uint32, charID uint32) ([]ShopItem, error) {
|
|
var result []ShopItem
|
|
err := r.db.Select(&result, `SELECT id, item_id, cost, quantity, min_hr, min_sr, min_gr, store_level, max_quantity,
|
|
COALESCE((SELECT bought FROM shop_items_bought WHERE shop_item_id=si.id AND character_id=$3), 0) as used_quantity,
|
|
road_floors, road_fatalis FROM shop_items si WHERE shop_type=$1 AND shop_id=$2
|
|
`, shopType, shopID, charID)
|
|
return result, err
|
|
}
|
|
|
|
// RecordPurchase upserts a purchase record, adding to the bought count.
|
|
func (r *ShopRepository) RecordPurchase(charID, shopItemID, quantity uint32) error {
|
|
_, err := r.db.Exec(`INSERT INTO shop_items_bought (character_id, shop_item_id, bought)
|
|
VALUES ($1,$2,$3) ON CONFLICT (character_id, shop_item_id)
|
|
DO UPDATE SET bought = shop_items_bought.bought + $3
|
|
`, charID, shopItemID, quantity)
|
|
return err
|
|
}
|
|
|
|
// GetFpointItem returns the quantity and fpoints cost for a frontier point item.
|
|
func (r *ShopRepository) GetFpointItem(tradeID uint32) (quantity, fpoints int, err error) {
|
|
err = r.db.QueryRow("SELECT quantity, fpoints FROM fpoint_items WHERE id=$1", tradeID).Scan(&quantity, &fpoints)
|
|
return
|
|
}
|
|
|
|
// GetFpointExchangeList returns all frontier point exchange items ordered by buyable status.
|
|
func (r *ShopRepository) GetFpointExchangeList() ([]FPointExchange, error) {
|
|
var result []FPointExchange
|
|
err := r.db.Select(&result, `SELECT id, item_type, item_id, quantity, fpoints, buyable FROM fpoint_items ORDER BY buyable DESC`)
|
|
return result, err
|
|
}
|