package postgres import ( "fmt" "git.snrd.de/Spaenny/steamServer" "github.com/jmoiron/sqlx" "github.com/google/uuid" ) type GamemodeStore struct { *sqlx.DB } func (s *GamemodeStore) Gamemode(name string) (steamServer.Gamemode, error) { var g steamServer.Gamemode if err := s.Get(&g, `SELECT * FROM gamemodes WHERE name = $1`, name); err != nil { return steamServer.Gamemode{}, fmt.Errorf("error getting gamemode id: %w", err) } return g, nil } func (s *GamemodeStore) Gamemodes() ([]steamServer.Gamemode, error) { var gg []steamServer.Gamemode var query = `SELECT * FROM public.gamemodes ORDER BY CASE name WHEN 'Deathmatch' THEN 1 WHEN 'MGE' THEN 2 WHEN 'Jumpserver' THEN 3 WHEN 'Casual' THEN 4 END` if err := s.Select(&gg, query); err != nil { return []steamServer.Gamemode{}, fmt.Errorf("error gettings servers: %w", err) } return gg, nil } func (s *GamemodeStore) GamemodeCount(region_id uuid.UUID) ([]steamServer.GamemodeCount, error) { var c []steamServer.GamemodeCount var query = `SELECT DISTINCT servers.gamemode_id, COUNT(DISTINCT servers.id) FROM servers, gamemodes WHERE servers.region_id = $1 GROUP BY servers.gamemode_id` if err := s.Select(&c, query, region_id); err != nil { return c, fmt.Errorf("error getting gamemode count: %w", err) } return c, nil }