BaseStatistics -> SqlStatistics.
This commit is contained in:
parent
e092a34055
commit
714a3790ee
@ -31,7 +31,7 @@ var (
|
||||
)
|
||||
|
||||
type SQLiteStatistics struct {
|
||||
statistics.BaseStatistics
|
||||
statistics.SqlStatistics
|
||||
}
|
||||
|
||||
func New(path string) (statistics.Statistics, error) {
|
||||
@ -41,7 +41,7 @@ func New(path string) (statistics.Statistics, error) {
|
||||
}
|
||||
|
||||
stats := &SQLiteStatistics{
|
||||
BaseStatistics: statistics.BaseStatistics{
|
||||
SqlStatistics: statistics.SqlStatistics{
|
||||
Db: db, DbDateFormat: dbDateFormat}}
|
||||
|
||||
db.Exec("PRAGMA foreign_keys = ON;")
|
||||
@ -52,31 +52,31 @@ func New(path string) (statistics.Statistics, error) {
|
||||
statistics.ErrPrepareStmt{Name: "initial schema"}.Error())
|
||||
}
|
||||
|
||||
stats.BaseStatistics.StmtSongAdd, err = db.Prepare(querySongAdd)
|
||||
stats.SqlStatistics.StmtSongAdd, err = db.Prepare(querySongAdd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err,
|
||||
statistics.ErrPrepareStmt{Name: "song_add"}.Error())
|
||||
}
|
||||
|
||||
stats.BaseStatistics.StmtHistoryAdd, err = db.Prepare(queryHistoryAdd)
|
||||
stats.SqlStatistics.StmtHistoryAdd, err = db.Prepare(queryHistoryAdd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err,
|
||||
statistics.ErrPrepareStmt{Name: "history_add"}.Error())
|
||||
}
|
||||
|
||||
stats.BaseStatistics.StmtLastNSongs, err = db.Prepare(queryLastNSongs)
|
||||
stats.SqlStatistics.StmtLastNSongs, err = db.Prepare(queryLastNSongs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err,
|
||||
statistics.ErrPrepareStmt{Name: "last N songs"}.Error())
|
||||
}
|
||||
|
||||
stats.BaseStatistics.StmtMostPopularSongs, err = db.Prepare(queryMostPopularSongs)
|
||||
stats.SqlStatistics.StmtMostPopularSongs, err = db.Prepare(queryMostPopularSongs)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err,
|
||||
statistics.ErrPrepareStmt{Name: "most popular song"}.Error())
|
||||
}
|
||||
|
||||
stats.BaseStatistics.StmtMostSimultaneousListeners, err = db.Prepare(queryMostSimultaneousListeners)
|
||||
stats.SqlStatistics.StmtMostSimultaneousListeners, err = db.Prepare(queryMostSimultaneousListeners)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err,
|
||||
statistics.ErrPrepareStmt{Name: "most simultaneous listeners"}.Error())
|
||||
@ -86,5 +86,5 @@ func New(path string) (statistics.Statistics, error) {
|
||||
}
|
||||
|
||||
func (s *SQLiteStatistics) Close() error {
|
||||
return s.BaseStatistics.Close()
|
||||
return s.SqlStatistics.Close()
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func (e ErrPrepareStmt) Error() string {
|
||||
var ErrNoSong = errors.New("no song was passed (a struct is nil or empty)")
|
||||
var ErrSongNotAdded = errors.New("song was not added")
|
||||
|
||||
type BaseStatistics struct {
|
||||
type SqlStatistics struct {
|
||||
Db *sql.DB
|
||||
DbDateFormat string
|
||||
|
||||
@ -42,7 +42,7 @@ type BaseStatistics struct {
|
||||
StmtMostSimultaneousListeners *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *BaseStatistics) Add(song *radio.Song) error {
|
||||
func (s *SqlStatistics) Add(song *radio.Song) error {
|
||||
if song == nil || song.Artist == "" || song.Title == "" {
|
||||
return ErrNoSong
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (s *BaseStatistics) Add(song *radio.Song) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BaseStatistics) LastNSongs(n int64) ([]radio.Song, error) {
|
||||
func (s *SqlStatistics) LastNSongs(n int64) ([]radio.Song, error) {
|
||||
if n == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@ -121,7 +121,7 @@ func (s *BaseStatistics) LastNSongs(n int64) ([]radio.Song, error) {
|
||||
return lst, nil
|
||||
}
|
||||
|
||||
func (s *BaseStatistics) MostNPopularSongs(n int64) ([]radio.Song, error) {
|
||||
func (s *SqlStatistics) MostNPopularSongs(n int64) ([]radio.Song, error) {
|
||||
if n == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@ -129,10 +129,10 @@ func (s *BaseStatistics) MostNPopularSongs(n int64) ([]radio.Song, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *BaseStatistics) MostSimultaneousListeners() (radio.Song, error) {
|
||||
func (s *SqlStatistics) MostSimultaneousListeners() (radio.Song, error) {
|
||||
return radio.Song{}, nil
|
||||
}
|
||||
|
||||
func (s *BaseStatistics) Close() error {
|
||||
func (s *SqlStatistics) Close() error {
|
||||
return s.Db.Close()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user