database

package
v0.2.3-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrActressMergeSameID           = errors.New("target_id and source_id must be different")
	ErrActressMergeInvalidID        = errors.New("target_id and source_id must be greater than 0")
	ErrActressMergeInvalidField     = errors.New("invalid merge field")
	ErrActressMergeInvalidDecision  = errors.New("invalid merge resolution")
	ErrActressMergeUniqueConstraint = errors.New("merge would violate unique constraints")
)

Functions

func ComputeMigrationHash

func ComputeMigrationHash(content []byte) string

func EnsureMigrationHashTable

func EnsureMigrationHashTable(db *sql.DB) error

func GetStoredHash

func GetStoredHash(db *sql.DB, name string) (string, error)

func HashMatches

func HashMatches(db *sql.DB, name string, content []byte) (bool, string, error)

func StoreMigrationHash

func StoreMigrationHash(db *sql.DB, name, hash string) error

Types

type ActressAliasRepository

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

ActressAliasRepository provides database operations for actress aliases

func NewActressAliasRepository

func NewActressAliasRepository(db *DB) *ActressAliasRepository

NewActressAliasRepository creates a new actress alias repository

func (*ActressAliasRepository) Create

func (r *ActressAliasRepository) Create(alias *models.ActressAlias) error

Create adds a new actress alias

func (*ActressAliasRepository) Delete

func (r *ActressAliasRepository) Delete(aliasName string) error

Delete removes an actress alias

func (*ActressAliasRepository) FindByAliasName

func (r *ActressAliasRepository) FindByAliasName(aliasName string) (*models.ActressAlias, error)

FindByAliasName finds a canonical name by alias

func (*ActressAliasRepository) FindByCanonicalName

func (r *ActressAliasRepository) FindByCanonicalName(canonicalName string) ([]models.ActressAlias, error)

FindByCanonicalName finds all aliases for a canonical name

func (*ActressAliasRepository) GetAliasMap

func (r *ActressAliasRepository) GetAliasMap() (map[string]string, error)

GetAliasMap returns all aliases as a map[aliasName]canonicalName

func (*ActressAliasRepository) List

List returns all actress aliases

func (*ActressAliasRepository) Upsert

func (r *ActressAliasRepository) Upsert(alias *models.ActressAlias) error

Upsert creates or updates an actress alias

type ActressAliasRepositoryInterface

type ActressAliasRepositoryInterface interface {
	Create(alias *models.ActressAlias) error
	Upsert(alias *models.ActressAlias) error
	FindByAliasName(aliasName string) (*models.ActressAlias, error)
	FindByCanonicalName(canonicalName string) ([]models.ActressAlias, error)
	List() ([]models.ActressAlias, error)
	Delete(aliasName string) error
	GetAliasMap() (map[string]string, error)
}

ActressAliasRepositoryInterface defines the contract for actress alias operations

type ActressMergeConflict

type ActressMergeConflict struct {
	Field             string      `json:"field"`
	TargetValue       interface{} `json:"target_value,omitempty"`
	SourceValue       interface{} `json:"source_value,omitempty"`
	DefaultResolution string      `json:"default_resolution"`
}

type ActressMergePreview

type ActressMergePreview struct {
	Target             models.Actress                  `json:"target"`
	Source             models.Actress                  `json:"source"`
	ProposedMerged     models.Actress                  `json:"proposed_merged"`
	Conflicts          []ActressMergeConflict          `json:"conflicts"`
	DefaultResolutions map[string]string               `json:"default_resolutions"`
	ConflictByField    map[string]ActressMergeConflict `json:"-"`
}

type ActressMergeResult

type ActressMergeResult struct {
	MergedActress     models.Actress `json:"merged_actress"`
	MergedFromID      uint           `json:"merged_from_id"`
	UpdatedMovies     int            `json:"updated_movies"`
	ConflictsResolved int            `json:"conflicts_resolved"`
	AliasesAdded      int            `json:"aliases_added"`
}

type ActressRepository

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

ActressRepository provides database operations for actresses

func NewActressRepository

func NewActressRepository(db *DB) *ActressRepository

NewActressRepository creates a new actress repository

func (*ActressRepository) Count

func (r *ActressRepository) Count() (int64, error)

Count returns total actresses in database.

func (*ActressRepository) CountSearch

func (r *ActressRepository) CountSearch(query string) (int64, error)

CountSearch returns count of actresses matching a query.

func (*ActressRepository) Create

func (r *ActressRepository) Create(actress *models.Actress) error

Create saves a new actress to the database

func (*ActressRepository) Delete

func (r *ActressRepository) Delete(id uint) error

Delete removes an actress by numeric ID.

func (*ActressRepository) FindByID

func (r *ActressRepository) FindByID(id uint) (*models.Actress, error)

FindByID finds an actress by numeric ID.

func (*ActressRepository) FindByJapaneseName

func (r *ActressRepository) FindByJapaneseName(name string) (*models.Actress, error)

FindByJapaneseName finds an actress by Japanese name

func (*ActressRepository) FindOrCreate

func (r *ActressRepository) FindOrCreate(actress *models.Actress) error

FindOrCreate finds an actress or creates a new one

func (*ActressRepository) List

func (r *ActressRepository) List(limit, offset int) ([]models.Actress, error)

List returns a paginated list of actresses

func (*ActressRepository) ListSorted

func (r *ActressRepository) ListSorted(limit, offset int, sortBy, sortOrder string) ([]models.Actress, error)

ListSorted returns a paginated list of actresses with explicit sorting.

func (*ActressRepository) Merge

func (r *ActressRepository) Merge(targetID, sourceID uint, resolutions map[string]string) (*ActressMergeResult, error)

func (*ActressRepository) PreviewMerge

func (r *ActressRepository) PreviewMerge(targetID, sourceID uint) (*ActressMergePreview, error)

func (*ActressRepository) Search

func (r *ActressRepository) Search(query string) ([]models.Actress, error)

Search searches for actresses by name (first, last, or Japanese name) If query is empty, returns all actresses (limited to 100)

func (*ActressRepository) SearchPaged

func (r *ActressRepository) SearchPaged(query string, limit, offset int) ([]models.Actress, error)

SearchPaged searches actresses by name and supports pagination.

func (*ActressRepository) SearchPagedSorted

func (r *ActressRepository) SearchPagedSorted(query string, limit, offset int, sortBy, sortOrder string) ([]models.Actress, error)

SearchPagedSorted searches actresses by name with pagination and explicit sorting.

func (*ActressRepository) Update

func (r *ActressRepository) Update(actress *models.Actress) error

Update updates an existing actress

type ActressRepositoryInterface

type ActressRepositoryInterface interface {
	Create(actress *models.Actress) error
	Update(actress *models.Actress) error
	FindByJapaneseName(name string) (*models.Actress, error)
	FindOrCreate(actress *models.Actress) error
	List(limit, offset int) ([]models.Actress, error)
	Search(query string) ([]models.Actress, error)
}

ActressRepositoryInterface defines the contract for actress database operations

type ContentIDMappingRepository

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

ContentIDMappingRepository provides database operations for content ID mappings

func NewContentIDMappingRepository

func NewContentIDMappingRepository(db *DB) *ContentIDMappingRepository

NewContentIDMappingRepository creates a new content ID mapping repository

func (*ContentIDMappingRepository) Create

Create saves a new content ID mapping to the database If a mapping with the same search ID already exists, it will be updated

func (*ContentIDMappingRepository) Delete

func (r *ContentIDMappingRepository) Delete(searchID string) error

Delete removes a content ID mapping from the database

func (*ContentIDMappingRepository) FindBySearchID

func (r *ContentIDMappingRepository) FindBySearchID(searchID string) (*models.ContentIDMapping, error)

FindBySearchID looks up a content ID mapping by the search ID Search IDs are normalized to uppercase for case-insensitive matching

func (*ContentIDMappingRepository) GetAll

GetAll retrieves all content ID mappings

type ContentIDMappingRepositoryInterface

type ContentIDMappingRepositoryInterface interface {
	FindBySearchID(searchID string) (*models.ContentIDMapping, error)
	Create(mapping *models.ContentIDMapping) error
	Delete(searchID string) error
	GetAll() ([]models.ContentIDMapping, error)
}

ContentIDMappingRepositoryInterface defines the contract for content ID mapping operations

type DB

type DB struct {
	*gorm.DB
	// contains filtered or unexported fields
}

DB wraps the GORM database connection

func New

func New(cfg *config.Config) (*DB, error)

New creates a new database connection

func (*DB) AutoMigrate

func (db *DB) AutoMigrate() error

AutoMigrate runs startup database migrations.

Kept for backward compatibility in tests and existing call sites. New runtime paths should call RunMigrationsOnStartup directly.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) RunMigrationsOnStartup

func (db *DB) RunMigrationsOnStartup(ctx context.Context) (err error)

RunMigrationsOnStartup applies all pending versioned database migrations.

The migration flow is fail-fast: - acquire startup migration lock - check pending migrations - create a pre-migration SQLite backup snapshot when pending work exists - apply migrations

type GenreReplacementRepository

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

GenreReplacementRepository provides database operations for genre replacements

func NewGenreReplacementRepository

func NewGenreReplacementRepository(db *DB) *GenreReplacementRepository

NewGenreReplacementRepository creates a new genre replacement repository

func (*GenreReplacementRepository) Create

func (r *GenreReplacementRepository) Create(replacement *models.GenreReplacement) error

Create adds a new genre replacement

func (*GenreReplacementRepository) Delete

func (r *GenreReplacementRepository) Delete(original string) error

Delete removes a genre replacement

func (*GenreReplacementRepository) FindByOriginal

func (r *GenreReplacementRepository) FindByOriginal(original string) (*models.GenreReplacement, error)

FindByOriginal finds a replacement by original genre name

func (*GenreReplacementRepository) GetReplacementMap

func (r *GenreReplacementRepository) GetReplacementMap() (map[string]string, error)

GetReplacementMap returns all replacements as a map[original]replacement

func (*GenreReplacementRepository) List

List returns all genre replacements

func (*GenreReplacementRepository) Upsert

func (r *GenreReplacementRepository) Upsert(replacement *models.GenreReplacement) error

Upsert creates or updates a genre replacement

type GenreReplacementRepositoryInterface

type GenreReplacementRepositoryInterface interface {
	Create(replacement *models.GenreReplacement) error
	Upsert(replacement *models.GenreReplacement) error
	FindByOriginal(original string) (*models.GenreReplacement, error)
	List() ([]models.GenreReplacement, error)
	Delete(original string) error
	GetReplacementMap() (map[string]string, error)
}

GenreReplacementRepositoryInterface defines the contract for genre replacement operations

type GenreRepository

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

GenreRepository provides database operations for genres

func NewGenreRepository

func NewGenreRepository(db *DB) *GenreRepository

NewGenreRepository creates a new genre repository

func (*GenreRepository) FindOrCreate

func (r *GenreRepository) FindOrCreate(name string) (*models.Genre, error)

FindOrCreate finds a genre or creates a new one

func (*GenreRepository) List

func (r *GenreRepository) List() ([]models.Genre, error)

List returns all genres

type HistoryRepository

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

HistoryRepository provides database operations for operation history

func NewHistoryRepository

func NewHistoryRepository(db *DB) *HistoryRepository

NewHistoryRepository creates a new history repository

func (*HistoryRepository) Count

func (r *HistoryRepository) Count() (int64, error)

Count returns the total number of history records

func (*HistoryRepository) CountByOperation

func (r *HistoryRepository) CountByOperation(operation string) (int64, error)

CountByOperation returns the count of records for a specific operation

func (*HistoryRepository) CountByStatus

func (r *HistoryRepository) CountByStatus(status string) (int64, error)

CountByStatus returns the count of records with a specific status

func (*HistoryRepository) Create

func (r *HistoryRepository) Create(history *models.History) error

Create adds a new history record

func (*HistoryRepository) Delete

func (r *HistoryRepository) Delete(id uint) error

Delete removes a history record

func (*HistoryRepository) DeleteByMovieID

func (r *HistoryRepository) DeleteByMovieID(movieID string) error

DeleteByMovieID removes all history records for a specific movie

func (*HistoryRepository) DeleteOlderThan

func (r *HistoryRepository) DeleteOlderThan(date time.Time) error

DeleteOlderThan removes history records older than the specified date

func (*HistoryRepository) FindByDateRange

func (r *HistoryRepository) FindByDateRange(start, end time.Time) ([]models.History, error)

FindByDateRange finds history records within a date range

func (*HistoryRepository) FindByID

func (r *HistoryRepository) FindByID(id uint) (*models.History, error)

FindByID finds a history record by ID

func (*HistoryRepository) FindByMovieID

func (r *HistoryRepository) FindByMovieID(movieID string) ([]models.History, error)

FindByMovieID finds all history records for a specific movie

func (*HistoryRepository) FindByOperation

func (r *HistoryRepository) FindByOperation(operation string, limit int) ([]models.History, error)

FindByOperation finds all history records for a specific operation type

func (*HistoryRepository) FindByStatus

func (r *HistoryRepository) FindByStatus(status string, limit int) ([]models.History, error)

FindByStatus finds all history records with a specific status

func (*HistoryRepository) FindRecent

func (r *HistoryRepository) FindRecent(limit int) ([]models.History, error)

FindRecent finds the most recent history records

func (*HistoryRepository) List

func (r *HistoryRepository) List(limit, offset int) ([]models.History, error)

List returns a paginated list of history records

type HistoryRepositoryInterface

type HistoryRepositoryInterface interface {
	Create(history *models.History) error
	FindByID(id uint) (*models.History, error)
	FindByMovieID(movieID string) ([]models.History, error)
	FindByOperation(operation string, limit int) ([]models.History, error)
	FindByStatus(status string, limit int) ([]models.History, error)
	FindRecent(limit int) ([]models.History, error)
	FindByDateRange(start, end time.Time) ([]models.History, error)
	Count() (int64, error)
	CountByStatus(status string) (int64, error)
	CountByOperation(operation string) (int64, error)
	Delete(id uint) error
	DeleteByMovieID(movieID string) error
	DeleteOlderThan(date time.Time) error
	List(limit, offset int) ([]models.History, error)
}

HistoryRepositoryInterface defines the contract for history tracking operations

type JobRepository

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

func NewJobRepository

func NewJobRepository(db *DB) *JobRepository

func (*JobRepository) Create

func (r *JobRepository) Create(job *models.Job) error

func (*JobRepository) Delete

func (r *JobRepository) Delete(id string) error

func (*JobRepository) DeleteOrganizedOlderThan

func (r *JobRepository) DeleteOrganizedOlderThan(date time.Time) error

func (*JobRepository) FindByID

func (r *JobRepository) FindByID(id string) (*models.Job, error)

func (*JobRepository) List

func (r *JobRepository) List() ([]models.Job, error)

func (*JobRepository) Update

func (r *JobRepository) Update(job *models.Job) error

type JobRepositoryInterface

type JobRepositoryInterface interface {
	Create(job *models.Job) error
	Update(job *models.Job) error
	FindByID(id string) (*models.Job, error)
	List() ([]models.Job, error)
	Delete(id string) error
	DeleteOrganizedOlderThan(date time.Time) error
}

JobRepositoryInterface defines the contract for job database operations

type MovieRepository

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

MovieRepository provides database operations for movies

func NewMovieRepository

func NewMovieRepository(db *DB) *MovieRepository

NewMovieRepository creates a new movie repository

func (*MovieRepository) Create

func (r *MovieRepository) Create(movie *models.Movie) error

Create saves a new movie to the database

func (*MovieRepository) Delete

func (r *MovieRepository) Delete(id string) error

Delete deletes a movie by ID

func (*MovieRepository) FindByContentID

func (r *MovieRepository) FindByContentID(contentID string) (*models.Movie, error)

FindByContentID finds a movie by its content ID

func (*MovieRepository) FindByID

func (r *MovieRepository) FindByID(id string) (*models.Movie, error)

FindByID finds a movie by its ID

func (*MovieRepository) List

func (r *MovieRepository) List(limit, offset int) ([]models.Movie, error)

List returns a paginated list of movies

func (*MovieRepository) Update

func (r *MovieRepository) Update(movie *models.Movie) error

Update updates an existing movie

func (*MovieRepository) Upsert

func (r *MovieRepository) Upsert(movie *models.Movie) error

Upsert creates a new movie or updates if it already exists (by ID)

type MovieRepositoryInterface

type MovieRepositoryInterface interface {
	Create(movie *models.Movie) error
	Update(movie *models.Movie) error
	Upsert(movie *models.Movie) error
	FindByID(id string) (*models.Movie, error)
	FindByContentID(contentID string) (*models.Movie, error)
	Delete(id string) error
	List(limit, offset int) ([]models.Movie, error)
}

MovieRepositoryInterface defines the contract for movie database operations

type MovieTagRepository

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

MovieTagRepository handles movie tag operations

func NewMovieTagRepository

func NewMovieTagRepository(db *DB) *MovieTagRepository

NewMovieTagRepository creates a new movie tag repository

func (*MovieTagRepository) AddTag

func (r *MovieTagRepository) AddTag(movieID, tag string) error

AddTag adds a tag to a movie Returns error if tag already exists (UNIQUE constraint violation)

func (*MovieTagRepository) GetMoviesWithTag

func (r *MovieTagRepository) GetMoviesWithTag(tag string) ([]string, error)

GetMoviesWithTag returns all movie IDs that have the specified tag

func (*MovieTagRepository) GetTagsForMovie

func (r *MovieTagRepository) GetTagsForMovie(movieID string) ([]string, error)

GetTagsForMovie returns all tags for a specific movie

func (*MovieTagRepository) GetUniqueTagsList

func (r *MovieTagRepository) GetUniqueTagsList() ([]string, error)

GetUniqueTagsList returns all unique tags in the database

func (*MovieTagRepository) ListAll

func (r *MovieTagRepository) ListAll() (map[string][]string, error)

ListAll returns a map of all movie IDs to their tags

func (*MovieTagRepository) RemoveAllTags

func (r *MovieTagRepository) RemoveAllTags(movieID string) error

RemoveAllTags removes all tags for a movie

func (*MovieTagRepository) RemoveTag

func (r *MovieTagRepository) RemoveTag(movieID, tag string) error

RemoveTag removes a specific tag from a movie

type MovieTagRepositoryInterface

type MovieTagRepositoryInterface interface {
	AddTag(movieID, tag string) error
	RemoveTag(movieID, tag string) error
	RemoveAllTags(movieID string) error
	GetTagsForMovie(movieID string) ([]string, error)
	GetMoviesWithTag(tag string) ([]string, error)
	ListAll() (map[string][]string, error)
	GetUniqueTagsList() ([]string, error)
}

MovieTagRepositoryInterface defines the contract for movie tag operations

type MovieTranslationRepository

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

MovieTranslationRepository provides database operations for movie translations

func NewMovieTranslationRepository

func NewMovieTranslationRepository(db *DB) *MovieTranslationRepository

NewMovieTranslationRepository creates a new movie translation repository

func (*MovieTranslationRepository) Delete

func (r *MovieTranslationRepository) Delete(movieID, language string) error

Delete deletes a translation

func (*MovieTranslationRepository) FindAllByMovie

func (r *MovieTranslationRepository) FindAllByMovie(movieID string) ([]models.MovieTranslation, error)

FindAllByMovie finds all translations for a specific movie

func (*MovieTranslationRepository) FindByMovieAndLanguage

func (r *MovieTranslationRepository) FindByMovieAndLanguage(movieID, language string) (*models.MovieTranslation, error)

FindByMovieAndLanguage finds a translation for a specific movie and language

func (*MovieTranslationRepository) Upsert

func (r *MovieTranslationRepository) Upsert(translation *models.MovieTranslation) error

Upsert creates a new translation or updates if it already exists (by MovieID + Language)

func (*MovieTranslationRepository) UpsertTx

func (r *MovieTranslationRepository) UpsertTx(tx *gorm.DB, translation *models.MovieTranslation) error

UpsertTx creates a new translation or updates if it already exists using the provided transaction

type MovieTranslationRepositoryInterface

type MovieTranslationRepositoryInterface interface {
	Upsert(translation *models.MovieTranslation) error
	UpsertTx(tx *gorm.DB, translation *models.MovieTranslation) error
	FindByMovieAndLanguage(movieID, language string) (*models.MovieTranslation, error)
	FindAllByMovie(movieID string) ([]models.MovieTranslation, error)
	Delete(movieID, language string) error
}

MovieTranslationRepositoryInterface defines the contract for movie translation operations

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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