示例#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) Vocaloids() ([]Vocaloid, error) {
	db := db.Get("default")
	var vocaloids []Vocaloid
	if err := db.Select(&vocaloids, db.Join(&SongVocaloid{}).On("Key").Where(&SongVocaloid{}, "VideoId", "=", m.VideoId)); err != nil {
		return nil, err
	}
	return vocaloids, nil
}
示例#3
0
文件: song.go 项目: naoina/vocanew
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
}
示例#4
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))
}
示例#5
0
func AllVocaloids() ([]*Vocaloid, error) {
	db := db.Get("default")
	var vocaloids []*Vocaloid
	return vocaloids, db.Select(&vocaloids, db.OrderBy("Order", genmai.ASC))
}