-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbfantasyheadtoheadstandings.go
94 lines (77 loc) · 3.13 KB
/
dbfantasyheadtoheadstandings.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package dbfantasyheadtoheadstandings
import (
"fmt"
"github.com/gkeele21/topdawgsportsAPI/internal/app/database"
)
type FantasyHeadToHeadStandings struct {
FantasyHeadToHeadStandingsID int64 `db:"fantasy_headtohead_standings_id"`
FantasyTeamID int64 `db:"fantasy_team_id"`
WeekID int64 `db:"week_id"`
WeekFantasyPts database.NullFloat64 `db:"week_fantasy_pts"`
TotalFantasyPts database.NullFloat64 `db:"total_fantasy_pts"`
WeekFantasyPtsAgainst database.NullFloat64 `db:"week_fantasy_pts_against"`
TotalFantasyPtsAgainst database.NullFloat64 `db:"total_fantasy_pts_against"`
Wins int64 `db:"wins"`
Losses int64 `db:"losses"`
Ties int64 `db:"ties"`
WeekHiScore database.NullInt64 `db:"week_hi_score"`
TotalHiScore database.NullInt64 `db:"total_hi_score"`
LeagueRanking database.NullInt64 `db:"league_ranking"`
CurrentStreak database.NullInt64 `db:"current_streak"`
LastFive database.NullString `db:"last_five"`
}
// ReadByID reads by id column
func ReadByID(ID int64) (*FantasyHeadToHeadStandings, error) {
d := FantasyHeadToHeadStandings{}
err := database.Get(&d, "SELECT * FROM fantasy_headtohead_standings where fantasy_headtohead_standings_id = ?", ID)
if err != nil {
return nil, err
}
return &d, nil
}
// ReadAll reads all records in the database
func ReadAll() ([]FantasyHeadToHeadStandings, error) {
var recs []FantasyHeadToHeadStandings
err := database.Select(&recs, "SELECT * FROM fantasy_headtohead_standings")
if err != nil {
return nil, err
}
return recs, nil
}
// Delete deletes a record from the database
func Delete(d *FantasyHeadToHeadStandings) error {
_, err := database.Exec("DELETE FROM fantasy_headtohead_standings WHERE fantasy_headtohead_standings_id = ?", d.FantasyHeadToHeadStandingsID)
if err != nil {
return fmt.Errorf("fantasy_headtohead_standings: couldn't delete record %s", err)
}
return nil
}
// Insert will create a new record in the database
func Insert(d *FantasyHeadToHeadStandings) error {
res, err := database.Exec(database.BuildInsert("fantasy_headtohead_standings", d), database.GetArguments(*d)...)
if err != nil {
return fmt.Errorf("fantasy_headtohead_standings: couldn't insert new %s", err)
}
ID, err := res.LastInsertId()
if err != nil {
return fmt.Errorf("fantasy_headtohead_standings: couldn't get last inserted ID %S", err)
}
d.FantasyHeadToHeadStandingsID = ID
return nil
}
// Update will update a record in the database
func Update(s *FantasyHeadToHeadStandings) error {
sql := database.BuildUpdate("fantasy_headtohead_standings", s)
_, err := database.Exec(sql, database.GetArgumentsForUpdate(*s)...)
if err != nil {
return fmt.Errorf("fantasy_headtohead_standings: couldn't update %s", err)
}
return nil
}
func Save(s *FantasyHeadToHeadStandings) error {
if s.FantasyHeadToHeadStandingsID > 0 {
return Update(s)
} else {
return Insert(s)
}
}