package postgres import ( "fmt" "git.snrd.de/Spaenny/steamServer" "github.com/google/uuid" "github.com/jmoiron/sqlx" ) type ServerStore struct { *sqlx.DB } func (s *ServerStore) Server(id uuid.UUID) (steamServer.Server, error) { var ser steamServer.Server if err := s.Get(&ser, `SELECT * FROM servers WHERE id = $1`, id); err != nil { return steamServer.Server{}, fmt.Errorf("error getting server: %w", err) } return ser, nil } func (s *ServerStore) Servers() ([]steamServer.Server, error) { var ss []steamServer.Server var query = `SELECT * FROM servers` if err := s.Select(&ss, query); err != nil { return []steamServer.Server{}, fmt.Errorf("error gettings servers: %w", err) } return ss, nil } func (s *ServerStore) CreateServer(ser *steamServer.Server) error { if err := s.Get(ser, `INSERT INTO servers VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNUNG *`, ser.ID, ser.RegionID, ser.GamemodeID, ser.AppID, ser.Name, ser.ServerIP, ser.Map, ser.Players, ser.MaxPlayers); err != nil { return fmt.Errorf("error creating server: %w", err) } return nil } func (s *ServerStore) UpdateServerByQuery(ser *steamServer.Server) error { fmt.Println(ser.Name + ser.Map) if err := s.Get(s, `UPDATE "servers" SET "name" = $1, "map" = $2, "players" = $3, "max_players" = $4 WHERE "name" = $1 RETURNING *`, ser.Name, ser.Map, ser.Players, ser.MaxPlayers); err != nil { return fmt.Errorf("error updating server: %w", err) } return nil }