Esempio n. 1
0
func AllByArtistId(artistId string) ([]*models.Release, error) {
	releases := make([]*models.Release, 0)
	rows, err := models.DB.Query(queryAllByArtistId, artistId)
	if err != nil {
		return releases, err
	}

	for rows.Next() {
		release := &models.Release{}

		var status *sql.NullString
		var _type *sql.NullString
		var packaging *sql.NullString
		var dateYear *sql.NullInt64
		var dateMonth *sql.NullInt64
		var dateDay *sql.NullInt64

		err := rows.Scan(&release.Id, &release.Name, &release.Comment, &status, &_type, &packaging, &dateYear, &dateMonth, &dateDay)
		if err != nil {
			return releases, err
		}

		if status != nil {
			release.Status = status.String
		}

		if _type != nil {
			release.Type = _type.String
		}

		if packaging != nil {
			release.Packaging = packaging.String
		}

		date := models.DatesToString(dateYear, dateMonth, dateDay)
		if date != "" {
			release.Date = date
		}

		releases = append(releases, release)
	}

	return releases, nil
}
Esempio n. 2
0
func ScanRecord(scanner Scanner, releaseGroup *models.ReleaseGroup) error {
	var _type *sql.NullString
	var firstReleaseDateYear *sql.NullInt64
	var firstReleaseDateMonth *sql.NullInt64
	var firstReleaseDateDay *sql.NullInt64

	err := scanner.Scan(&releaseGroup.Id, &releaseGroup.Name, &releaseGroup.Comment, &releaseGroup.ArtistCredit,
		&_type, &firstReleaseDateYear, &firstReleaseDateMonth, &firstReleaseDateDay)

	if err != nil {
		return err
	}

	date := models.DatesToString(firstReleaseDateYear, firstReleaseDateMonth, firstReleaseDateDay)
	if date != "" {
		releaseGroup.FirstReleaseDate = date
	}

	if _type != nil {
		releaseGroup.Type = _type.String
	}

	return nil
}