database

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the global database instance

Functions

func ClearAudioPreference

func ClearAudioPreference(db *gorm.DB, anilistID int) error

ClearAudioPreference removes per-show audio preference Called when show marked complete/dropped per CONTEXT.md

func ClearCompletedPreferences

func ClearCompletedPreferences(db *gorm.DB, anilistIDs []int) error

ClearCompletedPreferences batch-deletes preferences for AniList IDs Used by tracker sync when shows marked complete/dropped

func Close

func Close() error

Close closes the database connection

func GetAudioPreference

func GetAudioPreference(db *gorm.DB, anilistID int) (string, error)

GetAudioPreference retrieves per-show audio preference by AniList ID Returns empty string if no preference stored (not an error)

func GetDB

func GetDB() *gorm.DB

GetDB returns the database instance

func Init

func Init(cfg *config.DatabaseConfig) error

Init initializes the database connection

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs database migrations

func RunMigrations

func RunMigrations(db *gorm.DB) error

RunMigrations runs all pending database migrations

func SaveAudioPreference

func SaveAudioPreference(db *gorm.DB, anilistID int, preference string, trackIndex *int) error

SaveAudioPreference stores or updates per-show audio preference Upserts using GORM Save (updates if exists, inserts if new)

Types

type AniListMapping

type AniListMapping struct {
	ID              uint      `gorm:"primaryKey"`
	AniListID       int       `gorm:"column:anilist_id;not null;uniqueIndex"`
	ProviderName    string    `gorm:"not null"`
	ProviderMediaID string    `gorm:"not null"`
	Title           string    `gorm:"not null"`
	CreatedAt       time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	UpdatedAt       time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

AniListMapping represents the mapping between AniList media and provider media

func (AniListMapping) TableName

func (AniListMapping) TableName() string

TableName overrides the table name

type AudioPreference

type AudioPreference struct {
	ID         uint      `gorm:"primaryKey"`
	AniListID  int       `gorm:"column:anilist_id;not null;uniqueIndex"`
	Preference string    `gorm:"not null"` // "dub" or "sub"
	TrackIndex *int      `gorm:""`         // Optional: last selected mpv track index (advisory only)
	CreatedAt  time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	UpdatedAt  time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

AudioPreference stores per-show audio track preferences

func (AudioPreference) TableName

func (AudioPreference) TableName() string

TableName overrides the table name

type Download

type Download struct {
	ID              string     `gorm:"primaryKey"`
	MediaID         string     `gorm:"not null"`
	MediaTitle      string     `gorm:"not null"` // Title of the media
	MediaType       string     `gorm:"not null"` // Type (anime, movie, tv)
	Episode         int        `gorm:"not null"`
	Season          int        `gorm:"default:0"`
	Quality         string     `gorm:"not null"`
	Provider        string     `gorm:"not null"`
	Status          string     `gorm:"not null;index"` // queued, downloading, paused, completed, failed
	Progress        float64    `gorm:"default:0.0"`
	BytesDownloaded int64      `gorm:"default:0"` // Bytes downloaded
	TotalBytes      int64      `gorm:"default:0"` // Total bytes
	Speed           int64      `gorm:"default:0"` // Download speed (bytes/sec)
	Error           string     `gorm:""`          // Error message if failed
	FilePath        string     `gorm:""`
	CreatedAt       time.Time  `gorm:"default:CURRENT_TIMESTAMP"`
	StartedAt       *time.Time `gorm:""` // When download started
	CompletedAt     *time.Time `gorm:""`
}

Download represents a download task in the queue

func (Download) TableName

func (Download) TableName() string

TableName overrides the table name

type History

type History struct {
	ID              uint      `gorm:"primaryKey"`
	MediaID         string    `gorm:"not null;index"`
	MediaTitle      string    `gorm:"not null"`
	MediaType       string    `gorm:"not null;index"` // anime, movie, tv, manga
	Episode         int       `gorm:"default:0"`
	Season          int       `gorm:"default:0"`
	Page            int       `gorm:"default:0"` // For manga
	TotalPages      int       `gorm:"default:0"` // For manga
	ProgressSeconds int       `gorm:"not null"`
	TotalSeconds    int       `gorm:"not null"`
	ProgressPercent float64   `gorm:"not null"`
	WatchedAt       time.Time `gorm:"index;default:CURRENT_TIMESTAMP"`
	Completed       bool      `gorm:"default:false"`
	AniListID       *int      `gorm:"column:anilist_id;index;default:NULL"` // Optional AniList ID for tracking
	ProviderName    string    `gorm:"default:''"`                           // Provider used for this playback (FlixHQ, AllAnime, etc.)
}

History represents watch history for a media item

func (History) TableName

func (History) TableName() string

TableName overrides the table name

type Setting

type Setting struct {
	Key       string    `gorm:"primaryKey"`
	Value     string    `gorm:"not null"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

Setting represents a key-value store for application settings

func (Setting) TableName

func (Setting) TableName() string

TableName overrides the table name

type Statistic

type Statistic struct {
	ID             uint      `gorm:"primaryKey"`
	MediaID        string    `gorm:"not null;uniqueIndex"`
	MediaType      string    `gorm:"not null;index"`
	TotalWatchTime int       `gorm:"not null;default:0"` // seconds
	WatchCount     int       `gorm:"not null;default:1"`
	FirstWatched   time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	LastWatched    time.Time `gorm:"default:CURRENT_TIMESTAMP"`
	Genre          string    `gorm:""`
}

Statistic represents aggregate viewing statistics for a media item

func (Statistic) TableName

func (Statistic) TableName() string

TableName overrides the table name

type SyncQueue

type SyncQueue struct {
	ID        uint       `gorm:"primaryKey"`
	MediaID   string     `gorm:"not null"`
	AniListID *int       `gorm:""`
	Episode   int        `gorm:"not null"`
	Progress  float64    `gorm:"not null"`
	Status    string     `gorm:""` // watching, completed, etc.
	Score     *float64   `gorm:""`
	Synced    bool       `gorm:"default:false;index"`
	CreatedAt time.Time  `gorm:"default:CURRENT_TIMESTAMP"`
	SyncedAt  *time.Time `gorm:""`
}

SyncQueue represents items waiting to be synced to tracking services

func (SyncQueue) TableName

func (SyncQueue) TableName() string

TableName overrides the table name

Jump to

Keyboard shortcuts

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