Exemplo n.º 1
0
func (repo *PgLeagueRepository) FindAll() ([]model.League, error) {
	rows, err := repo.manager.db.Query(`SELECT id, name, sport, created, modified
        FROM league`)

	if err != nil {
		return []model.League{}, err
	}

	var leagues []model.League
	for rows.Next() {
		league, err := marshal.League(rows)
		if err != nil {
			return []model.League{}, err
		}

		if leagues == nil {
			leagues = make([]model.League, 1, 10)
		}

		leagues = append(leagues, *league)
	}

	err = rows.Err()
	if err != nil {
		return []model.League{}, err
	}

	return leagues, nil
}
Exemplo n.º 2
0
func (repo *PgLeagueRepository) FindById(id int) (*model.League, error) {
	row := repo.manager.db.QueryRow(`SELECT id, name, sport, created, modified
        FROM league
        WHERE id = $1`, id)

	league, err := marshal.League(row)
	if err != nil {
		return nil, err
	}

	return league, nil
}