db

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: 17 Imported by: 0

Documentation

Overview

Package db provides database models and data access functions.

Package db provides database models and data access functions.

Package db provides database models and data access functions.

Package db provides database models and data access functions.

Package db provides database models and data access functions.

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is

Functions

func AddTagToPodcast

func AddTagToPodcast(id, tagID string) error

AddTagToPodcast add tag to podcast.

func AssertNoPodcastsExist

func AssertNoPodcastsExist(t *testing.T, database *gorm.DB)

AssertNoPodcastsExist verifies the database has no podcasts.

func AssertPodcastItemCount

func AssertPodcastItemCount(t *testing.T, database *gorm.DB, podcastID string, expectedCount int)

AssertPodcastItemCount verifies the expected number of podcast items exist.

func CreatePodcast

func CreatePodcast(podcast *Podcast) error

CreatePodcast create podcast.

func CreatePodcastItem

func CreatePodcastItem(podcastItem *PodcastItem) error

CreatePodcastItem create podcast item.

func CreateTag

func CreateTag(tag *Tag) error

CreateTag create tag.

func DeletePodcastByID

func DeletePodcastByID(id string) error

DeletePodcastByID delete podcast by id.

func DeletePodcastItemByID

func DeletePodcastItemByID(id string) error

DeletePodcastItemByID delete podcast item by id.

func DeleteTagByID

func DeleteTagByID(id string) error

DeleteTagByID delete tag by id.

func ExecuteAndSaveMigration

func ExecuteAndSaveMigration(mig localMigration) error

ExecuteAndSaveMigration execute and save migration.

func ForceSetLastEpisodeDate

func ForceSetLastEpisodeDate(podcastID string)

ForceSetLastEpisodeDate force set last episode date.

func GetAllPodcastItems

func GetAllPodcastItems(podcasts *[]PodcastItem) error

GetAllPodcastItems get all podcast items.

func GetAllPodcastItemsAlreadyDownloaded

func GetAllPodcastItemsAlreadyDownloaded() (*[]PodcastItem, error)

GetAllPodcastItemsAlreadyDownloaded get all podcast items already downloaded.

func GetAllPodcastItemsByIDs

func GetAllPodcastItemsByIDs(podcastItemIDs []string) (*[]PodcastItem, error)

GetAllPodcastItemsByIDs get all podcast items by ids.

func GetAllPodcastItemsByPodcastID

func GetAllPodcastItemsByPodcastID(podcastID string, podcastItems *[]PodcastItem) error

GetAllPodcastItemsByPodcastID get all podcast items by podcast id.

func GetAllPodcastItemsByPodcastIDs

func GetAllPodcastItemsByPodcastIDs(podcastIDs []string, podcastItems *[]PodcastItem) error

GetAllPodcastItemsByPodcastIDs get all podcast items by podcast ids.

func GetAllPodcastItemsToBeDownloaded

func GetAllPodcastItemsToBeDownloaded() (*[]PodcastItem, error)

GetAllPodcastItemsToBeDownloaded get all podcast items to be downloaded.

func GetAllPodcastItemsWithoutImage

func GetAllPodcastItemsWithoutImage() (*[]PodcastItem, error)

GetAllPodcastItemsWithoutImage get all podcast items without image.

func GetAllPodcastItemsWithoutSize

func GetAllPodcastItemsWithoutSize() (*[]PodcastItem, error)

GetAllPodcastItemsWithoutSize get all podcast items without size.

func GetAllPodcasts

func GetAllPodcasts(podcasts *[]Podcast, sorting string) error

GetAllPodcasts get all podcasts.

func GetAllTags

func GetAllTags(sorting string) (*[]Tag, error)

GetAllTags get all tags.

func GetDB

func GetDB() *gorm.DB

GetDB returns the database connection for creating a connection pool.

func GetEpisodeNumber

func GetEpisodeNumber(podcastItemID, podcastID string) (int, error)

GetEpisodeNumber get episode number.

func GetPaginatedPodcastItems

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

GetPaginatedPodcastItems get paginated podcast items.

func GetPaginatedPodcastItemsNew

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

GetPaginatedPodcastItemsNew get paginated podcast items new.

func GetPaginatedTags

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

GetPaginatedTags get paginated tags.

func GetPodcastByID

func GetPodcastByID(id string, podcast *Podcast) error

GetPodcastByID get podcast by id.

func GetPodcastByTitleAndAuthor

func GetPodcastByTitleAndAuthor(title, author string, podcast *Podcast) error

GetPodcastByTitleAndAuthor get podcast by title and author.

func GetPodcastByURL

func GetPodcastByURL(url string, podcast *Podcast) error

GetPodcastByURL get podcast by u r l.

func GetPodcastEpisodeStats

func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, error)

GetPodcastEpisodeStats get podcast episode stats.

func GetPodcastItemByID

func GetPodcastItemByID(id string, podcastItem *PodcastItem) error

GetPodcastItemByID get podcast item by id.

func GetPodcastItemByPodcastIDAndGUID

func GetPodcastItemByPodcastIDAndGUID(podcastID, guid string, podcastItem *PodcastItem) error

GetPodcastItemByPodcastIDAndGUID get podcast item by podcast id and g u i d.

func GetPodcastItemsByPodcastIDAndGUIDs

func GetPodcastItemsByPodcastIDAndGUIDs(podcastID string, guids []string) (*[]PodcastItem, error)

GetPodcastItemsByPodcastIDAndGUIDs get podcast items by podcast id and g u i ds.

func GetPodcastsByURLList

func GetPodcastsByURLList(urls []string, podcasts *[]Podcast) error

GetPodcastsByURLList get podcasts by u r l list.

func GetTagsByIDs

func GetTagsByIDs(ids []string) (*[]Tag, error)

GetTagsByIDs get tags by ids.

func Init

func Init() (*gorm.DB, error)

Init is used to Initialize Database

func Lock

func Lock(name string, duration int)

Lock lock.

func Migrate

func Migrate()

Migrate Database

func RemoveTagFromPodcast

func RemoveTagFromPodcast(id, tagID string) error

RemoveTagFromPodcast remove tag from podcast.

func RunMigrations

func RunMigrations()

RunMigrations run migrations.

func SetAllEpisodesToDownload

func SetAllEpisodesToDownload(podcastID string) error

SetAllEpisodesToDownload set all episodes to download.

func SetupTestDB

func SetupTestDB(t *testing.T) *gorm.DB

SetupTestDB creates an in-memory SQLite database for testing. It automatically runs migrations and returns the database connection. The database is isolated per test and will be cleaned up automatically.

func TeardownTestDB

func TeardownTestDB(t *testing.T, database *gorm.DB)

TeardownTestDB closes the database connection and cleans up resources.

func TogglePodcastPauseStatus

func TogglePodcastPauseStatus(podcastID string, isPaused bool) error

TogglePodcastPauseStatus toggle podcast pause status.

func Unlock

func Unlock(name string)

Unlock unlock.

func UnlockMissedJobs

func UnlockMissedJobs()

UnlockMissedJobs unlock missed jobs.

func UntagAllByTagID

func UntagAllByTagID(tagID string) error

UntagAllByTagID untag all by tag id.

func UpdateLastEpisodeDateForPodcast

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

UpdateLastEpisodeDateForPodcast update last episode date for podcast.

func UpdatePodcast

func UpdatePodcast(podcast *Podcast) error

UpdatePodcast update podcast.

func UpdatePodcastItem

func UpdatePodcastItem(podcastItem *PodcastItem) error

UpdatePodcastItem update podcast item.

func UpdatePodcastItemFileSize

func UpdatePodcastItemFileSize(podcastItemID string, size int64) error

UpdatePodcastItemFileSize update podcast item file size.

func UpdateSettings

func UpdateSettings(setting *Setting) error

UpdateSettings update settings.

func UpdateTag

func UpdateTag(tag *Tag) error

UpdateTag update tag.

Types

type Base

type Base struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `gorm:"index"`
	ID        string     `sql:"type:uuid;primary_key"`
}

Base is

func (*Base) BeforeCreate

func (base *Base) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID for new records before database insertion

type DownloadStatus

type DownloadStatus int

DownloadStatus represents the download state of a podcast episode.

const (
	// NotDownloaded indicates the episode has not been downloaded yet.
	NotDownloaded DownloadStatus = iota
	// Downloading indicates the episode is currently being downloaded.
	Downloading
	// Downloaded indicates the episode has been successfully downloaded.
	Downloaded
	// Deleted indicates the episode file has been removed.
	Deleted
)

Download status constants.

type JobLock

type JobLock struct {
	Base
	Date     time.Time
	Name     string
	Duration int
}

JobLock represents job lock data.

func GetLock

func GetLock(name string) *JobLock

GetLock get lock.

func (*JobLock) IsLocked

func (lock *JobLock) IsLocked() bool

IsLocked returns true if the job lock is currently active.

type Migration

type Migration struct {
	Base
	Date time.Time
	Name string
}

Migration represents migration data.

type Podcast

type Podcast struct {
	Base
	Title string

	Summary string `gorm:"type:text"`

	Author string

	Image string

	URL string

	LastEpisode *time.Time

	PodcastItems []PodcastItem

	Tags []*Tag `gorm:"many2many:podcast_tags;"`

	DownloadedEpisodesCount  int `gorm:"-"`
	DownloadingEpisodesCount int `gorm:"-"`
	AllEpisodesCount         int `gorm:"-"`

	DownloadedEpisodesSize  int64 `gorm:"-"`
	DownloadingEpisodesSize int64 `gorm:"-"`
	AllEpisodesSize         int64 `gorm:"-"`

	IsPaused bool `gorm:"default:false"`
}

Podcast is

func AssertPodcastExists

func AssertPodcastExists(t *testing.T, database *gorm.DB, url string) *Podcast

AssertPodcastExists verifies a podcast exists with the given URL.

func CreateTestPodcast

func CreateTestPodcast(t *testing.T, database *gorm.DB, overrides ...*Podcast) *Podcast

CreateTestPodcast creates a test podcast with default values.

type PodcastItem

type PodcastItem struct {
	Base
	PubDate        time.Time
	BookmarkDate   time.Time
	DownloadDate   time.Time
	FileURL        string
	PodcastID      string
	LocalImage     string
	Summary        string `gorm:"type:text"`
	Title          string
	GUID           string
	Image          string
	EpisodeType    string
	DownloadPath   string
	Podcast        Podcast
	DownloadStatus DownloadStatus `gorm:"default:0"`
	Duration       int
	FileSize       int64
	IsPlayed       bool `gorm:"default:false"`
}

PodcastItem is

func CreateTestPodcastItem

func CreateTestPodcastItem(t *testing.T, database *gorm.DB, podcastID string, overrides ...*PodcastItem) *PodcastItem

CreateTestPodcastItem creates a test podcast item with default values.

type PodcastItemConsolidateDiskStatsModel

type PodcastItemConsolidateDiskStatsModel struct {
	Downloaded      int64
	Downloading     int64
	NotDownloaded   int64
	Deleted         int64
	PendingDownload int64
}

PodcastItemConsolidateDiskStatsModel represents podcast item consolidate disk stats model data.

func GetPodcastEpisodeDiskStats

func GetPodcastEpisodeDiskStats() (PodcastItemConsolidateDiskStatsModel, error)

GetPodcastEpisodeDiskStats get podcast episode disk stats.

type PodcastItemDiskStatsModel

type PodcastItemDiskStatsModel struct {
	DownloadStatus DownloadStatus
	Count          int
	Size           int64
}

PodcastItemDiskStatsModel represents podcast item disk stats model data.

type PodcastItemStatsModel

type PodcastItemStatsModel struct {
	PodcastID      string
	DownloadStatus DownloadStatus
	Count          int
	Size           int64
}

PodcastItemStatsModel represents podcast item stats model data.

type Setting

type Setting struct {
	Base
	FileNameFormat              string `gorm:"default:%EpisodeTitle%"`
	UserAgent                   string
	BaseURL                     string
	InitialDownloadCount        int  `gorm:"default:5"`
	MaxDownloadConcurrency      int  `gorm:"default:5"`
	MaxDownloadKeep             int  `gorm:"default:0"`
	DarkMode                    bool `gorm:"default:false"`
	DownloadEpisodeImages       bool `gorm:"default:false"`
	GenerateNFOFile             bool `gorm:"default:false"`
	DontDownloadDeletedFromDisk bool `gorm:"default:false"`
	AutoDownload                bool `gorm:"default:true"`
	DownloadOnAdd               bool `gorm:"default:true"`
	PassthroughPodcastGUID      bool `gorm:"default:false"`
}

Setting represents setting data.

func CreateTestSetting

func CreateTestSetting(t *testing.T, database *gorm.DB) *Setting

CreateTestSetting creates test settings with default values.

func GetOrCreateSetting

func GetOrCreateSetting() *Setting

GetOrCreateSetting get or create setting.

type Tag

type Tag struct {
	Base
	Label       string
	Description string     `gorm:"type:text"`
	Podcasts    []*Podcast `gorm:"many2many:podcast_tags;"`
}

Tag represents tag data.

func CreateTestTag

func CreateTestTag(t *testing.T, database *gorm.DB, label string) *Tag

CreateTestTag creates a test tag with default values.

func GetTagByID

func GetTagByID(id string) (*Tag, error)

GetTagByID get tag by id.

func GetTagByLabel

func GetTagByLabel(label string) (*Tag, error)

GetTagByLabel get tag by label.

Jump to

Keyboard shortcuts

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