func GameWithTeams(row MultiScanner) (*model.Game, error) { var game model.Game var homeLeague model.League var awayLeague model.League var season model.Season var home model.Team var away model.Team err := row.Scan(&game.ID, &season.ID, &game.StartTime, &game.HomeScore, &game.AwayScore, &game.Created, &game.Modified, &home.ID, &homeLeague.ID, &home.Name, &home.Created, &home.Modified, &away.ID, &awayLeague.ID, &away.Name, &away.Created, &away.Modified) if err != nil { return nil, err } home.League = &homeLeague away.League = &awayLeague game.Season = &season game.HomeTeam = &home game.AwayTeam = &away return &game, nil }
func Team(row MultiScanner) (*model.Team, error) { //t.id, t.name, t.created, t.modified, l.id, l.name, l.sport, l.created, l.modified var team model.Team var league model.League err := row.Scan(&team.ID, &league.ID, &team.Name, &team.Created, &team.Modified) if err != nil { return nil, err } team.League = &league return &team, nil }
func (repo *PgRepository) CreateTeam(team *model.Team) error { err := team.Validate(repo) if err != nil { return err } t := time.Now() var id int err = repo.manager.db.QueryRow(`INSERT INTO team(league_id, name, created, modified) VALUES($1, $2, $3, $4) RETURNING id`, team.League.ID, team.Name, t, t).Scan(&id) if err != nil { return err } team.ID = id team.Created = t team.Modified = t return nil }