29 lines
770 B
Go
29 lines
770 B
Go
package postgres
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.snrd.de/Spaenny/steamServer"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
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 gamemodes ORDER BY name ASC`
|
|
if err := s.Select(&gg, query); err != nil {
|
|
return []steamServer.Gamemode{}, fmt.Errorf("error gettings servers: %w", err)
|
|
}
|
|
return gg, nil
|
|
}
|