Esempio n. 1
0
func (repo *PgRepository) CreateStanding(standing *model.Standing) error {
	err := standing.Validate(repo)
	if err != nil {
		return err
	}

	t := time.Now()

	var id int
	err = repo.manager.db.QueryRow(`INSERT INTO standing(season_id, team_id, wins, losses, ties, created, modified)
	    VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING id`,
		standing.Season.ID, standing.Team.ID, standing.Wins, standing.Losses, standing.Ties, t, t).Scan(&id)

	if err != nil {
		return err
	}

	standing.ID = id
	standing.Created = t
	standing.Modified = t

	return nil
}