From 714a3790eef17c7415603709ea9962cd733ac54d Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 31 Dec 2024 00:24:29 +0400 Subject: [PATCH] BaseStatistics -> SqlStatistics. --- internal/statistics/db/sqlite/db.go | 16 ++++++++-------- internal/statistics/statistics.go | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/statistics/db/sqlite/db.go b/internal/statistics/db/sqlite/db.go index 1dcbad7..0102e5f 100644 --- a/internal/statistics/db/sqlite/db.go +++ b/internal/statistics/db/sqlite/db.go @@ -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() } diff --git a/internal/statistics/statistics.go b/internal/statistics/statistics.go index 5e9b706..ee7c9e4 100644 --- a/internal/statistics/statistics.go +++ b/internal/statistics/statistics.go @@ -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() }