db

package
v0.0.0-...-21615fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2015 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migration001AddBaseData

func Migration001AddBaseData(tx *gorm.DB) error

Migration001AddBaseData adds the baseline quality groups.

func RunMigrations

func RunMigrations(dbh *gorm.DB)

RunMigrations will run all migrations.

TODO: make this a little more sophisticated.

Types

type Episode

type Episode struct {
	ID                  int64 `gorm:"column:id; primary_key:yes"`
	Show                Show
	ShowId              int64
	Name                string
	Season              int64
	Episode             int64
	Description         string
	AirDate             time.Time
	HasNFO              bool `gorm:"column:has_nfo"`
	HasTBN              bool `gorm:"column:has_tbn"`
	Status              types.EpisodeStatus
	Quality             quality.Quality
	Location            string
	FileSize            int64
	ReleaseName         string
	SceneSeason         int64
	SceneEpisode        int64
	AbsoluteNumber      int64
	SceneAbsoluteNumber int64
	Version             int64
	ReleaseGroup        string
}

Episode represents an individual episode of a Show

func (*Episode) AfterFind

func (e *Episode) AfterFind() error

AfterFind fixes the SQLite driver sets everything to local

func (*Episode) AirDateString

func (e *Episode) AirDateString() string

AirDateString returns the episode's airdate as a YYYY-MM-DD date if set. Otherwise it returns the empty string.

func (*Episode) BeforeSave

func (e *Episode) BeforeSave() error

BeforeSave performs validation on the record before saving

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle controls access to the database and makes sure only one operation is in process at a time.

func NewDBHandle

func NewDBHandle(dbPath string, verbose bool, writeUpdates bool) *Handle

NewDBHandle creates a new DBHandle

dbPath: the path to the database to use.
verbose: when true database accesses are logged to stdout
writeUpdates: when true actually write to the databse (useful for testing)

func NewMemoryDBHandle

func NewMemoryDBHandle(verbose bool, writeUpdates bool) *Handle

NewMemoryDBHandle creates a new in memory database. Useful for testing.

func (*Handle) AddShow

func (h *Handle) AddShow(s *Show) error

AddShow adds the given show to the Database

func (*Handle) GetAllShows

func (h *Handle) GetAllShows() ([]Show, error)

GetAllShows returns all shows in the database.

func (*Handle) GetEpisodeByID

func (h *Handle) GetEpisodeByID(episodeid int64) (*Episode, error)

GetEpisodeByID returns an episode with the given ID or an error if it doesn't exist.

func (*Handle) GetEpisodeByShowSeasonAndNumber

func (h *Handle) GetEpisodeByShowSeasonAndNumber(showid, season, number int64) (*Episode, error)

GetEpisodeByShowSeasonAndNumber does exactly what it says.

func (*Handle) GetLastPollTime

func (h *Handle) GetLastPollTime(name string) time.Time

GetLastPollTime returns the last time recorded for the given name. If there is no record it returns a zero value time.Time

func (*Handle) GetQualityGroupFromStringOrDefault

func (h *Handle) GetQualityGroupFromStringOrDefault(name string) *quality.QualityGroup

GetQualityGroupFromStringOrDefault tries to find a matching QualityGroup with the given name. If that doesn't exist it returns the first one with the Default bit set. If _that_ fails it will return (and create inthe db) the hardcoded default.

func (*Handle) GetQualityGroups

func (h *Handle) GetQualityGroups() ([]quality.QualityGroup, error)

GetQualityGroups returns all quality groups.

func (*Handle) GetShowByAllNames

func (h *Handle) GetShowByAllNames(name string) (*Show, int64, error)

GetShowByAllNames tries to find a show that matches the given name using alternate spelling and associated show names from various SceneException providers.

It returns the Show, a season override if that given name maps to a particular season of the show (common for Anime) and an error if one occured.

func (*Handle) GetShowByID

func (h *Handle) GetShowByID(showID int64) (*Show, error)

GetShowByID returs the show with the given ID or an error if it doesn't exist.

func (*Handle) GetShowByIndexerAndID

func (h *Handle) GetShowByIndexerAndID(indexer string, indexerID int64) (*Show, error)

GetShowByIndexerAndID returns the show with the given indexer and indexerid or an error if it doesn't exist.

func (*Handle) GetShowByName

func (h *Handle) GetShowByName(name string) (*Show, error)

GetShowByName returns the show with the given name (and it's episodes) or an error if not found.

func (*Handle) GetShowByNameIgnoreCase

func (h *Handle) GetShowByNameIgnoreCase(name string) (*Show, error)

GetShowByNameIgnoreCase returns the show with the given name (and it's episodes) or an error if not found.

func (*Handle) GetShowEpisodes

func (h *Handle) GetShowEpisodes(s *Show) ([]Episode, error)

GetShowEpisodes returns all of the given show's episodes

func (*Handle) GetShowFromNameException

func (h *Handle) GetShowFromNameException(name string) (*Show, int64, error)

GetShowFromNameException will try to match (ignoring case) the given name to a known Name Exception. If found it will then try to match that to a Show by matching the indexer and indexerid.

func (*Handle) NextAirdateForShow

func (h *Handle) NextAirdateForShow(dbshow *Show) *time.Time

NextAirdateForShow returns the date of the next episode for this show.

func (*Handle) SaveEpisode

func (h *Handle) SaveEpisode(e *Episode) error

SaveEpisode saves the given episode to the database

func (*Handle) SaveEpisodes

func (h *Handle) SaveEpisodes(eps []*Episode) error

SaveEpisodes save the list of episodes to the database. This is done in a transaction which will be much faster if the number of episodes is large.

func (*Handle) SaveNameExceptions

func (h *Handle) SaveNameExceptions(source string, excepts []*NameException) error

SaveNameExceptions saves all the given exceptions, totally replacing the exceptions for the given source.

func (*Handle) SaveShow

func (h *Handle) SaveShow(s *Show) error

SaveShow saves the show (and any episodes) to the database

func (*Handle) SetLastPollTime

func (h *Handle) SetLastPollTime(name string) error

SetLastPollTime records the current time for the given name.

type LastPollTime

type LastPollTime struct {
	Name          string
	LastRefreshed time.Time
}

LastPollTime stores the last time we polled a particular provider.

func (*LastPollTime) AfterFind

func (s *LastPollTime) AfterFind() error

AfterFind updates all times to UTC because SQLite driver sets everything to local

type NameException

type NameException struct {
	ID        int64
	Source    string
	Indexer   string
	IndexerID int64
	Name      string
	Season    int64
	CreatedAt time.Time
	UpdatedAt time.Time
}

NameException stores alternate names of shows to use when parsing input files.

func (*NameException) BeforeSave

func (e *NameException) BeforeSave() error

BeforeSave ensures that all fields are set to non default values.

type Show

type Show struct {
	ID                int64  `gorm:"column:id; primary_key:yes"`
	Name              string `sql:"not null"`
	Description       string
	Indexer           string `sql:"not null"`
	IndexerID         int64  `gorm:"column:indexer_key"` // id to use when looking up with the indexer
	Episodes          []Episode
	Location          string // Location of Show on disk
	Network           string
	Genre             string // pipe seperated
	Classification    string
	Runtime           int64 // in minutes
	QualityGroup      quality.QualityGroup
	QualityGroupID    int64
	Airs              string // Hour of the day
	Status            string
	FlattenFolders    bool
	Paused            bool
	StartYear         int
	AirByDate         bool
	Language          string
	Subtitles         bool
	ImdbID            string
	Sports            bool
	Anime             bool
	Scene             bool
	DefaultEpStatus   types.EpisodeStatus
	LastIndexerUpdate time.Time
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

Show is a TV Show

func LoadFixtures

func LoadFixtures(t TestReporter, d *Handle) []Show

LoadFixtures adds a base set of Fixtures to the given database.

func (*Show) AfterFind

func (s *Show) AfterFind() error

AfterFind updates all times to UTC because SQLite driver sets everything to local

func (*Show) BeforeSave

func (s *Show) BeforeSave() error

BeforeSave validates a show before writing it to the database

type TestReporter

type TestReporter interface {
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

TestReporter is a shim interface so we don't need to include the testing package in the compiled binary

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL