Fetch the show title while fetching an episode

This commit is contained in:
Grégoire Delattre 2020-04-11 17:29:42 +02:00
parent 8e8a1dc3e9
commit 57b70eb585

View File

@ -26,8 +26,12 @@ const (
FROM episodes WHERE show_imdb_id=$1;` FROM episodes WHERE show_imdb_id=$1;`
getEpisodeQuery = ` getEpisodeQuery = `
SELECT * SELECT s.title show_title, e.*
FROM episodes WHERE show_imdb_id=$1 AND season=$2 AND episode=$3;` FROM shows s , episodes e
WHERE s.imdb_id = e.show_imdb_id
AND e.show_imdb_id=$1
AND e.season=$2
AND e.episode=$3;`
) )
// episodeDB represents the Episode in the DB // episodeDB represents the Episode in the DB
@ -37,6 +41,7 @@ type episodeDB struct {
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
ShowImdbID string `db:"show_imdb_id"` ShowImdbID string `db:"show_imdb_id"`
ShowTvdbID int `db:"show_tvdb_id"` ShowTvdbID int `db:"show_tvdb_id"`
ShowTitle string `db:"show_title"`
Season int `db:"season"` Season int `db:"season"`
Episode int `db:"episode"` Episode int `db:"episode"`
Title string `db:"title"` Title string `db:"title"`
@ -71,6 +76,7 @@ func FillEpisodeFromDB(eDB *episodeDB, pEpisode *polochon.ShowEpisode) {
// Keep the data that never changes but only if we have it // Keep the data that never changes but only if we have it
updateIfNonEmpty(&pEpisode.EpisodeImdbID, eDB.ImdbID) updateIfNonEmpty(&pEpisode.EpisodeImdbID, eDB.ImdbID)
updateIfNonEmpty(&pEpisode.ShowImdbID, eDB.ShowImdbID) updateIfNonEmpty(&pEpisode.ShowImdbID, eDB.ShowImdbID)
updateIfNonEmpty(&pEpisode.ShowTitle, eDB.ShowTitle)
updateIfNonZeroInt(&pEpisode.TvdbID, eDB.TvdbID) updateIfNonZeroInt(&pEpisode.TvdbID, eDB.TvdbID)
updateIfNonZeroInt(&pEpisode.ShowTvdbID, eDB.ShowTvdbID) updateIfNonZeroInt(&pEpisode.ShowTvdbID, eDB.ShowTvdbID)
pEpisode.Season = eDB.Season pEpisode.Season = eDB.Season