database

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package database provides abstractions for database operations. This package defines repository interfaces that enable dependency injection and testing with mock implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repository

type Repository interface {
	// Podcast operations
	GetPodcastByURL(url string, podcast *db.Podcast) error
	GetPodcastsByURLList(urls []string, podcasts *[]db.Podcast) error
	GetAllPodcasts(podcasts *[]db.Podcast, sorting string) error
	GetPodcastByID(id string, podcast *db.Podcast) error
	GetPodcastByTitleAndAuthor(title, author string, podcast *db.Podcast) error
	CreatePodcast(podcast *db.Podcast) error
	UpdatePodcast(podcast *db.Podcast) error
	DeletePodcastByID(id string) error
	UpdateLastEpisodeDateForPodcast(podcastID string, lastEpisode time.Time) error
	ForceSetLastEpisodeDate(podcastID string)
	TogglePodcastPauseStatus(podcastID string, isPaused bool) error
	SetAllEpisodesToDownload(podcastID string) error

	// PodcastItem operations
	GetAllPodcastItems(podcasts *[]db.PodcastItem) error
	GetAllPodcastItemsWithoutSize() (*[]db.PodcastItem, error)
	GetPaginatedPodcastItemsNew(queryModel *model.EpisodesFilter) (*[]db.PodcastItem, int64, error)
	GetPaginatedPodcastItems(page, count int, downloadedOnly, playedOnly *bool, fromDate time.Time, podcasts *[]db.PodcastItem, total *int64) error
	GetPodcastItemByID(id string, podcastItem *db.PodcastItem) error
	GetAllPodcastItemsByPodcastID(podcastID string, podcastItems *[]db.PodcastItem) error
	GetAllPodcastItemsByPodcastIDs(podcastIDs []string, podcastItems *[]db.PodcastItem) error
	GetAllPodcastItemsByIDs(podcastItemIDs []string) (*[]db.PodcastItem, error)
	GetPodcastItemsByPodcastIDAndGUIDs(podcastID string, guids []string) (*[]db.PodcastItem, error)
	GetPodcastItemByPodcastIDAndGUID(podcastID, guid string, podcastItem *db.PodcastItem) error
	GetAllPodcastItemsWithoutImage() (*[]db.PodcastItem, error)
	GetAllPodcastItemsToBeDownloaded() (*[]db.PodcastItem, error)
	GetAllPodcastItemsAlreadyDownloaded() (*[]db.PodcastItem, error)
	CreatePodcastItem(podcastItem *db.PodcastItem) error
	UpdatePodcastItem(podcastItem *db.PodcastItem) error
	UpdatePodcastItemFileSize(podcastItemID string, size int64) error
	DeletePodcastItemByID(id string) error
	GetEpisodeNumber(podcastItemID, podcastID string) (int, error)

	// Stats operations
	GetPodcastEpisodeStats() (*[]db.PodcastItemStatsModel, error)
	GetPodcastEpisodeDiskStats() (db.PodcastItemConsolidateDiskStatsModel, error)

	// Tag operations
	GetAllTags(sorting string) (*[]db.Tag, error)
	GetPaginatedTags(page, count int, tags *[]db.Tag, total *int64) error
	GetTagByID(id string) (*db.Tag, error)
	GetTagsByIDs(ids []string) (*[]db.Tag, error)
	GetTagByLabel(label string) (*db.Tag, error)
	CreateTag(tag *db.Tag) error
	UpdateTag(tag *db.Tag) error
	DeleteTagByID(id string) error
	AddTagToPodcast(id, tagID string) error
	RemoveTagFromPodcast(id, tagID string) error
	UntagAllByTagID(tagID string) error

	// Settings operations
	GetOrCreateSetting() *db.Setting
	UpdateSettings(setting *db.Setting) error

	// Job lock operations
	GetLock(name string) *db.JobLock
	Lock(name string, duration int)
	Unlock(name string)
	UnlockMissedJobs()
}

Repository defines the interface for all database operations. This abstraction enables dependency injection and testing with mocks.

type SQLiteRepository

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

SQLiteRepository implements Repository interface using GORM with SQLite. This is a thin wrapper around the existing db package functions to enable dependency injection and testing.

func NewDefaultSQLiteRepository

func NewDefaultSQLiteRepository() *SQLiteRepository

NewDefaultSQLiteRepository creates a repository using the global DB connection. This maintains backwards compatibility with existing code.

func NewSQLiteRepository

func NewSQLiteRepository(database *gorm.DB) *SQLiteRepository

NewSQLiteRepository creates a new SQLite repository instance.

func (*SQLiteRepository) AddTagToPodcast

func (r *SQLiteRepository) AddTagToPodcast(id, tagID string) error

AddTagToPodcast associates a tag with a podcast.

func (*SQLiteRepository) CreatePodcast

func (r *SQLiteRepository) CreatePodcast(podcast *db.Podcast) error

CreatePodcast creates a new podcast record.

func (*SQLiteRepository) CreatePodcastItem

func (r *SQLiteRepository) CreatePodcastItem(podcastItem *db.PodcastItem) error

CreatePodcastItem creates a new podcast episode record.

func (*SQLiteRepository) CreateTag

func (r *SQLiteRepository) CreateTag(tag *db.Tag) error

CreateTag creates a new tag record.

func (*SQLiteRepository) DeletePodcastByID

func (r *SQLiteRepository) DeletePodcastByID(id string) error

DeletePodcastByID deletes a podcast by its ID.

func (*SQLiteRepository) DeletePodcastItemByID

func (r *SQLiteRepository) DeletePodcastItemByID(id string) error

DeletePodcastItemByID deletes an episode by its ID.

func (*SQLiteRepository) DeleteTagByID

func (r *SQLiteRepository) DeleteTagByID(id string) error

DeleteTagByID deletes a tag by its ID.

func (*SQLiteRepository) ForceSetLastEpisodeDate

func (r *SQLiteRepository) ForceSetLastEpisodeDate(podcastID string)

ForceSetLastEpisodeDate forces the last episode date to be recalculated.

func (*SQLiteRepository) GetAllPodcastItems

func (r *SQLiteRepository) GetAllPodcastItems(podcasts *[]db.PodcastItem) error

GetAllPodcastItems retrieves all podcast episodes.

func (*SQLiteRepository) GetAllPodcastItemsAlreadyDownloaded

func (r *SQLiteRepository) GetAllPodcastItemsAlreadyDownloaded() (*[]db.PodcastItem, error)

GetAllPodcastItemsAlreadyDownloaded retrieves all downloaded episodes.

func (*SQLiteRepository) GetAllPodcastItemsByIDs

func (r *SQLiteRepository) GetAllPodcastItemsByIDs(podcastItemIDs []string) (*[]db.PodcastItem, error)

GetAllPodcastItemsByIDs retrieves episodes by their IDs in specified order.

func (*SQLiteRepository) GetAllPodcastItemsByPodcastID

func (r *SQLiteRepository) GetAllPodcastItemsByPodcastID(podcastID string, podcastItems *[]db.PodcastItem) error

GetAllPodcastItemsByPodcastID retrieves all episodes for a specific podcast.

func (*SQLiteRepository) GetAllPodcastItemsByPodcastIDs

func (r *SQLiteRepository) GetAllPodcastItemsByPodcastIDs(podcastIDs []string, podcastItems *[]db.PodcastItem) error

GetAllPodcastItemsByPodcastIDs retrieves episodes for multiple podcasts.

func (*SQLiteRepository) GetAllPodcastItemsToBeDownloaded

func (r *SQLiteRepository) GetAllPodcastItemsToBeDownloaded() (*[]db.PodcastItem, error)

GetAllPodcastItemsToBeDownloaded retrieves episodes queued for download.

func (*SQLiteRepository) GetAllPodcastItemsWithoutImage

func (r *SQLiteRepository) GetAllPodcastItemsWithoutImage() (*[]db.PodcastItem, error)

GetAllPodcastItemsWithoutImage retrieves episodes without downloaded images.

func (*SQLiteRepository) GetAllPodcastItemsWithoutSize

func (r *SQLiteRepository) GetAllPodcastItemsWithoutSize() (*[]db.PodcastItem, error)

GetAllPodcastItemsWithoutSize retrieves episodes without file size information.

func (*SQLiteRepository) GetAllPodcasts

func (r *SQLiteRepository) GetAllPodcasts(podcasts *[]db.Podcast, sorting string) error

GetAllPodcasts retrieves all podcasts with optional sorting.

func (*SQLiteRepository) GetAllTags

func (r *SQLiteRepository) GetAllTags(sorting string) (*[]db.Tag, error)

GetAllTags retrieves all tags with optional sorting.

func (*SQLiteRepository) GetEpisodeNumber

func (r *SQLiteRepository) GetEpisodeNumber(podcastItemID, podcastID string) (int, error)

GetEpisodeNumber retrieves the sequential episode number within a podcast.

func (*SQLiteRepository) GetLock

func (r *SQLiteRepository) GetLock(name string) *db.JobLock

GetLock retrieves a job lock by name.

func (*SQLiteRepository) GetOrCreateSetting

func (r *SQLiteRepository) GetOrCreateSetting() *db.Setting

GetOrCreateSetting retrieves or creates the application settings record.

func (*SQLiteRepository) GetPaginatedPodcastItems

func (r *SQLiteRepository) GetPaginatedPodcastItems(page, count int, downloadedOnly, playedOnly *bool, fromDate time.Time, podcasts *[]db.PodcastItem, total *int64) error

GetPaginatedPodcastItems retrieves paginated episodes with basic filtering.

func (*SQLiteRepository) GetPaginatedPodcastItemsNew

func (r *SQLiteRepository) GetPaginatedPodcastItemsNew(queryModel *model.EpisodesFilter) (*[]db.PodcastItem, int64, error)

GetPaginatedPodcastItemsNew retrieves paginated episodes with advanced filtering.

func (*SQLiteRepository) GetPaginatedTags

func (r *SQLiteRepository) GetPaginatedTags(page, count int, tags *[]db.Tag, total *int64) error

GetPaginatedTags retrieves paginated tags.

func (*SQLiteRepository) GetPodcastByID

func (r *SQLiteRepository) GetPodcastByID(id string, podcast *db.Podcast) error

GetPodcastByID retrieves a podcast by its ID.

func (*SQLiteRepository) GetPodcastByTitleAndAuthor

func (r *SQLiteRepository) GetPodcastByTitleAndAuthor(title, author string, podcast *db.Podcast) error

GetPodcastByTitleAndAuthor retrieves a podcast by its title and author.

func (*SQLiteRepository) GetPodcastByURL

func (r *SQLiteRepository) GetPodcastByURL(url string, podcast *db.Podcast) error

GetPodcastByURL retrieves a podcast by its RSS feed URL.

func (*SQLiteRepository) GetPodcastEpisodeDiskStats

func (r *SQLiteRepository) GetPodcastEpisodeDiskStats() (db.PodcastItemConsolidateDiskStatsModel, error)

GetPodcastEpisodeDiskStats retrieves consolidated disk usage statistics.

func (*SQLiteRepository) GetPodcastEpisodeStats

func (r *SQLiteRepository) GetPodcastEpisodeStats() (*[]db.PodcastItemStatsModel, error)

GetPodcastEpisodeStats retrieves episode statistics grouped by podcast and download status.

func (*SQLiteRepository) GetPodcastItemByID

func (r *SQLiteRepository) GetPodcastItemByID(id string, podcastItem *db.PodcastItem) error

GetPodcastItemByID retrieves a podcast episode by its ID.

func (*SQLiteRepository) GetPodcastItemByPodcastIDAndGUID

func (r *SQLiteRepository) GetPodcastItemByPodcastIDAndGUID(podcastID, guid string, podcastItem *db.PodcastItem) error

GetPodcastItemByPodcastIDAndGUID retrieves an episode by podcast ID and GUID.

func (*SQLiteRepository) GetPodcastItemsByPodcastIDAndGUIDs

func (r *SQLiteRepository) GetPodcastItemsByPodcastIDAndGUIDs(podcastID string, guids []string) (*[]db.PodcastItem, error)

GetPodcastItemsByPodcastIDAndGUIDs retrieves episodes by podcast ID and GUIDs.

func (*SQLiteRepository) GetPodcastsByURLList

func (r *SQLiteRepository) GetPodcastsByURLList(urls []string, podcasts *[]db.Podcast) error

GetPodcastsByURLList retrieves multiple podcasts by their RSS feed URLs.

func (*SQLiteRepository) GetTagByID

func (r *SQLiteRepository) GetTagByID(id string) (*db.Tag, error)

GetTagByID retrieves a tag by its ID.

func (*SQLiteRepository) GetTagByLabel

func (r *SQLiteRepository) GetTagByLabel(label string) (*db.Tag, error)

GetTagByLabel retrieves a tag by its label.

func (*SQLiteRepository) GetTagsByIDs

func (r *SQLiteRepository) GetTagsByIDs(ids []string) (*[]db.Tag, error)

GetTagsByIDs retrieves multiple tags by their IDs.

func (*SQLiteRepository) Lock

func (r *SQLiteRepository) Lock(name string, duration int)

Lock acquires a lock for a job with specified duration.

func (*SQLiteRepository) RemoveTagFromPodcast

func (r *SQLiteRepository) RemoveTagFromPodcast(id, tagID string) error

RemoveTagFromPodcast removes a tag association from a podcast.

func (*SQLiteRepository) SetAllEpisodesToDownload

func (r *SQLiteRepository) SetAllEpisodesToDownload(podcastID string) error

SetAllEpisodesToDownload marks all deleted episodes as ready for download.

func (*SQLiteRepository) TogglePodcastPauseStatus

func (r *SQLiteRepository) TogglePodcastPauseStatus(podcastID string, isPaused bool) error

TogglePodcastPauseStatus toggles the pause status of a podcast.

func (*SQLiteRepository) Unlock

func (r *SQLiteRepository) Unlock(name string)

Unlock releases a lock for a job.

func (*SQLiteRepository) UnlockMissedJobs

func (r *SQLiteRepository) UnlockMissedJobs()

UnlockMissedJobs releases locks for jobs that have exceeded their duration.

func (*SQLiteRepository) UntagAllByTagID

func (r *SQLiteRepository) UntagAllByTagID(tagID string) error

UntagAllByTagID removes all podcast associations for a tag.

func (*SQLiteRepository) UpdateLastEpisodeDateForPodcast

func (r *SQLiteRepository) UpdateLastEpisodeDateForPodcast(podcastID string, lastEpisode time.Time) error

UpdateLastEpisodeDateForPodcast updates the last episode date for a podcast.

func (*SQLiteRepository) UpdatePodcast

func (r *SQLiteRepository) UpdatePodcast(podcast *db.Podcast) error

UpdatePodcast updates an existing podcast record.

func (*SQLiteRepository) UpdatePodcastItem

func (r *SQLiteRepository) UpdatePodcastItem(podcastItem *db.PodcastItem) error

UpdatePodcastItem updates an existing podcast episode record.

func (*SQLiteRepository) UpdatePodcastItemFileSize

func (r *SQLiteRepository) UpdatePodcastItemFileSize(podcastItemID string, size int64) error

UpdatePodcastItemFileSize updates the file size of an episode.

func (*SQLiteRepository) UpdateSettings

func (r *SQLiteRepository) UpdateSettings(setting *db.Setting) error

UpdateSettings updates the application settings record.

func (*SQLiteRepository) UpdateTag

func (r *SQLiteRepository) UpdateTag(tag *db.Tag) error

UpdateTag updates an existing tag record.

Jump to

Keyboard shortcuts

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