示例#1
0
func (repo *MockSeasonRepository) Create(season *model.Season) error {
	err := season.Validate(repo)
	if err != nil {
		return err
	}

	id := repo.lastId + 1
	season.Id = id
	repo.lastId = id

	t := time.Now()
	season.Created = t
	season.Modified = t

	repo.mocks[id] = season

	return nil
}
示例#2
0
func (repo *PgSeasonRepository) Create(season *model.Season) error {
	err := season.Validate(repo)
	if err != nil {
		return err
	}

	t := time.Now()

	var id int
	err = repo.manager.db.QueryRow(`INSERT INTO season(league_id, name, start_date, end_date, created, modified) 
	    VALUES($1, $2, $3, $4, $5, $6) RETURNING id`,
		season.League.Id, season.Name, season.Start_date, season.End_date, t, t).Scan(&id)

	if err != nil {
		return err
	}

	season.Id = id
	season.Created = t
	season.Modified = t

	return nil
}