예제 #1
0
파일: song.go 프로젝트: naoina/vocanew
func (m *Song) Count(vocaloids ...*Vocaloid) (int64, error) {
	db := db.Get("default")
	var count int64
	if len(vocaloids) < 1 {
		return count, db.Select(&count, db.Count("Id"), db.From(&Song{}))
	}
	where := db.Where("Key", "=", vocaloids[0].Key)
	for _, v := range vocaloids[1:] {
		where = where.Or(db.Where("Key", "=", v.Key))
	}
	return count, db.Select(&count, db.Count("Id"), db.From(&SongVocaloid{}), where)
}
예제 #2
0
파일: song.go 프로젝트: naoina/vocanew
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))
}