forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.go
54 lines (46 loc) · 1.25 KB
/
team.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
//
// Model and datastore CRUD methods for a team at an event.
package main
type Team struct {
Id int
Name string
Nickname string
City string
StateProv string
Country string
RookieYear int
RobotName string
Accomplishments string
WpaKey string
YellowCard bool
}
func (database *Database) CreateTeam(team *Team) error {
return database.teamMap.Insert(team)
}
func (database *Database) GetTeamById(id int) (*Team, error) {
team := new(Team)
err := database.teamMap.Get(team, id)
if err != nil && err.Error() == "sql: no rows in result set" {
team = nil
err = nil
}
return team, err
}
func (database *Database) SaveTeam(team *Team) error {
_, err := database.teamMap.Update(team)
return err
}
func (database *Database) DeleteTeam(team *Team) error {
_, err := database.teamMap.Delete(team)
return err
}
func (database *Database) TruncateTeams() error {
return database.teamMap.TruncateTables()
}
func (database *Database) GetAllTeams() ([]Team, error) {
var teams []Team
err := database.teamMap.Select(&teams, "SELECT * FROM teams ORDER BY id")
return teams, err
}