2020-01-15 23:49:09 +01:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
import (
|
2020-01-28 14:22:17 +01:00
|
|
|
"context"
|
2020-01-15 23:49:09 +01:00
|
|
|
|
2020-01-28 14:22:17 +01:00
|
|
|
. "github.com/Masterminds/squirrel"
|
2020-01-15 23:49:09 +01:00
|
|
|
"github.com/astaxie/beego/orm"
|
2020-01-24 01:44:08 +01:00
|
|
|
"github.com/navidrome/navidrome/model"
|
2020-01-15 23:49:09 +01:00
|
|
|
)
|
|
|
|
|
2020-01-19 21:37:41 +01:00
|
|
|
type genreRepository struct {
|
2020-01-28 14:22:17 +01:00
|
|
|
sqlRepository
|
2020-01-19 21:37:41 +01:00
|
|
|
}
|
2020-01-15 23:49:09 +01:00
|
|
|
|
2020-01-28 14:22:17 +01:00
|
|
|
func NewGenreRepository(ctx context.Context, o orm.Ormer) model.GenreRepository {
|
|
|
|
r := &genreRepository{}
|
|
|
|
r.ctx = ctx
|
|
|
|
r.ormer = o
|
|
|
|
r.tableName = "media_file"
|
|
|
|
return r
|
2020-01-15 23:49:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r genreRepository) GetAll() (model.Genres, error) {
|
2020-01-28 14:22:17 +01:00
|
|
|
sq := Select("genre as name", "count(distinct album_id) as album_count", "count(distinct id) as song_count").
|
|
|
|
From("media_file").GroupBy("genre")
|
2020-01-31 22:47:13 +01:00
|
|
|
res := model.Genres{}
|
2020-02-01 20:48:22 +01:00
|
|
|
err := r.queryAll(sq, &res)
|
2020-01-28 14:22:17 +01:00
|
|
|
return res, err
|
2020-01-15 23:49:09 +01:00
|
|
|
}
|