Пример #1
0
func (m *Song) LatestUpdate() (time.Time, error) {
	db := db.Get("default")
	var songs []Song
	if err := db.Select(&songs, db.OrderBy("Id", genmai.DESC).Limit(1)); err != nil {
		return time.Time{}, err
	}
	return songs[0].AddTime, nil
}
Пример #2
0
func (m *Song) FindByVocaloid(vocaloids []*Vocaloid, offset, limit int) ([]*Song, error) {
	var songs []*Song
	db := db.Get("default")
	if len(vocaloids) == 0 {
		return songs, db.Select(&songs, db.Distinct("*"), db.OrderBy("Id", genmai.DESC).Offset(offset).Limit(limit))
	}
	keys := make([]interface{}, len(vocaloids))
	for i, v := range vocaloids {
		keys[i] = v.Key
	}
	var songVocaloids []SongVocaloid
	if err := db.Select(&songVocaloids, db.Distinct("VideoId"), db.Where("Key").In(keys...), db.OrderBy("Id", genmai.DESC).Offset(offset).Limit(limit)); err != nil {
		return nil, err
	}
	keys = keys[:0]
	for _, sv := range songVocaloids {
		keys = append(keys, sv.VideoId)
	}
	return songs, db.Select(&songs, db.Distinct("*"), db.Where("VideoId").In(keys...), db.OrderBy("Id", genmai.DESC))
}
Пример #3
0
func AllVocaloids() ([]*Vocaloid, error) {
	db := db.Get("default")
	var vocaloids []*Vocaloid
	return vocaloids, db.Select(&vocaloids, db.OrderBy("Order", genmai.ASC))
}