aliases

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GenreConfig = ResourceConfig{
		AliasTable:    "genre_aliases",
		ResourceFK:    "genre_id",
		ResourceTable: "genres",
	}
	TagConfig = ResourceConfig{
		AliasTable:    "tag_aliases",
		ResourceFK:    "tag_id",
		ResourceTable: "tags",
	}
	SeriesConfig = ResourceConfig{
		AliasTable:    "series_aliases",
		ResourceFK:    "series_id",
		ResourceTable: "series",
	}
	PersonConfig = ResourceConfig{
		AliasTable:    "person_aliases",
		ResourceFK:    "person_id",
		ResourceTable: "persons",
	}
	PublisherConfig = ResourceConfig{
		AliasTable:    "publisher_aliases",
		ResourceFK:    "publisher_id",
		ResourceTable: "publishers",
	}
)

Functions

func FindResourceIDByAlias

func FindResourceIDByAlias(ctx context.Context, db bun.IDB, cfg ResourceConfig, name string, libraryID int) (int, error)

FindResourceIDByAlias looks up a resource ID by checking alias names (case-insensitive). Returns the resource ID if found, or sql.ErrNoRows if no alias matches.

func TransferAliasesOnMerge

func TransferAliasesOnMerge(ctx context.Context, db bun.IDB, cfg ResourceConfig, sourceID, targetID int) error

TransferAliasesOnMerge reassigns the source resource's aliases to the target and adds the source's primary name as a new alias of the target, owned by the target's Library. Duplicates (case-insensitive match against the target's primary name or existing aliases) are silently left for CASCADE to clean up when the source is deleted. When the source's name is already an alias of a third resource in the target's Library, that alias stays where it is and the target does not get it, since the alias table allows each name once per Library. Accepts bun.IDB so it works inside a transaction.

Types

type ResourceConfig

type ResourceConfig struct {
	AliasTable    string
	ResourceFK    string
	ResourceTable string
}

type Service

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

func NewService

func NewService(db *bun.DB) *Service

func (*Service) AddAlias

func (svc *Service) AddAlias(ctx context.Context, cfg ResourceConfig, resourceID int, name string, libraryID int) error

func (*Service) ListAliases

func (svc *Service) ListAliases(ctx context.Context, cfg ResourceConfig, resourceID int) ([]string, error)

func (*Service) RemoveAlias

func (svc *Service) RemoveAlias(ctx context.Context, cfg ResourceConfig, resourceID int, name string) error

func (*Service) RemoveAllAliases

func (svc *Service) RemoveAllAliases(ctx context.Context, cfg ResourceConfig, resourceID int) error

func (*Service) SyncAliases

func (svc *Service) SyncAliases(ctx context.Context, cfg ResourceConfig, resourceID int, libraryID int, desired []string) error

Jump to

Keyboard shortcuts

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