Help us shape the future of Go! Take the 2026 Go Developer Survey

database

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package database provides SQLite and Postgres-protocol access for outtake.

Index

Constants

View Source
const (
	// BackendSQLite is the default libsql/SQLite backend.
	BackendSQLite = "sqlite"
	// BackendPostgres is the Postgres-protocol backend.
	BackendPostgres = "postgres"
	// BackendPgx is an alias for the Postgres-protocol backend.
	BackendPgx = "pgx"
)

Variables

View Source
var (
	// ErrClipProfileNotFound is returned when a clip profile row does not exist.
	ErrClipProfileNotFound = errors.New("clip profile not found")

	// ErrLastClipProfile is returned when deleting the only remaining profile.
	ErrLastClipProfile = errors.New("cannot delete the last clip profile")
)
View Source
var ErrClipNotFound = errors.New("clip not found")

ErrClipNotFound is returned when a clip row does not exist.

Functions

This section is empty.

Types

type ClipProfile

type ClipProfile struct {
	ID        string
	Name      string
	CRF       int
	Preset    string
	AudioKbps int
	MaxWidth  int
	IsDefault bool
	CreatedAt time.Time
	UpdatedAt time.Time
}

ClipProfile is a user-managed clip encode profile.

func (ClipProfile) QualityPreset

func (profile ClipProfile) QualityPreset() clip.QualityPreset

QualityPreset returns ffmpeg settings for a stored profile.

Returns:

  • preset: The encoder settings this profile describes.

type DB

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

DB represents a database connection.

func New

func New(dbPath string) (*DB, error)

New creates a new SQLite database instance.

Parameters:

  • dbPath: Path to the SQLite database file.

Returns:

  • db: A migrated database handle.
  • err: Non-nil when the database cannot be opened or migrated.

func NewFromConfig

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

NewFromConfig constructs the database backend selected by configuration.

Parameters:

  • cfg: The loaded configuration naming the backend.

Returns:

  • db: A migrated database handle.
  • err: Non-nil when the backend is unknown, unconfigured, or cannot be opened.

func (*DB) ClearAuth

func (db *DB) ClearAuth(ctx context.Context) error

ClearAuth deletes stored Plex tokens and the selected server.

Parameters:

  • ctx: Request scope for the transaction.

Returns:

  • err: Non-nil when either delete or the commit fails.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

Returns:

  • err: Non-nil when the connection cannot be closed.

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn returns the underlying database connection.

Returns:

  • conn: The pooled connection this database queries through.

func (*DB) DefaultClipProfile

func (db *DB) DefaultClipProfile(ctx context.Context) (ClipProfile, error)

DefaultClipProfile returns the profile marked default, or Medium built-in.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • profile: The default profile, falling back to the Medium built-in.
  • err: Non-nil when the read fails or the built-in profile is missing.

func (*DB) DeleteClip

func (db *DB) DeleteClip(ctx context.Context, id string) error

DeleteClip removes a clip row.

Parameters:

  • ctx: Request scope for the write.
  • id: Identifier of the clip to remove.

Returns:

  • err: Non-nil when the row cannot be deleted.

func (*DB) DeleteClipProfile

func (db *DB) DeleteClipProfile(ctx context.Context, id string) error

DeleteClipProfile removes a profile and keeps a default assigned.

Parameters:

  • ctx: Request scope for the write.
  • id: Identifier of the profile to remove.

Returns:

  • err: ErrLastClipProfile when it is the only profile, otherwise the write failure.

func (*DB) GetClip

func (db *DB) GetClip(ctx context.Context, id string) (*clip.Job, error)

GetClip loads a job by ID.

Parameters:

  • ctx: Request scope for the read.
  • id: Identifier of the job to load.

Returns:

  • job: The stored render.
  • err: ErrClipNotFound when no row matches, otherwise the read failure.

func (*DB) GetClipProfile

func (db *DB) GetClipProfile(ctx context.Context, id string) (ClipProfile, error)

GetClipProfile loads a clip profile by ID.

Parameters:

  • ctx: Request scope for the read.
  • id: Identifier of the profile to load.

Returns:

  • profile: The stored clip profile.
  • err: ErrClipProfileNotFound when no row matches, otherwise the read failure.

func (*DB) LatestToken

func (db *DB) LatestToken(ctx context.Context) (string, error)

LatestToken returns the most recently stored Plex token.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • token: The newest stored token, or empty when none is stored.
  • err: Non-nil when the read fails.

func (*DB) ListClipProfiles

func (db *DB) ListClipProfiles(ctx context.Context) ([]ClipProfile, error)

ListClipProfiles returns clip profiles with the default first.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • profiles: The stored clip profiles.
  • err: Non-nil when the rows cannot be read.

func (*DB) ListClips

func (db *DB) ListClips(ctx context.Context) ([]*clip.Job, error)

ListClips returns every job ordered by creation time, newest first.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • jobs: The stored renders.
  • err: Non-nil when the rows cannot be read.

func (*DB) ListClipsForMedia

func (db *DB) ListClipsForMedia(ctx context.Context, mediaID string) ([]*clip.Job, error)

ListClipsForMedia returns the jobs created from a media item.

Parameters:

  • ctx: Request scope for the read.
  • mediaID: Identifier of the source media item.

Returns:

  • jobs: The renders made from that item.
  • err: Non-nil when the rows cannot be read.

func (*DB) ListPendingClips

func (db *DB) ListPendingClips(ctx context.Context) ([]*clip.Job, error)

ListPendingClips returns jobs that still need processing.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • jobs: The pending and processing renders, oldest first.
  • err: Non-nil when the rows cannot be read.

func (*DB) SaveClip

func (db *DB) SaveClip(ctx context.Context, job *clip.Job) error

SaveClip inserts or replaces a job.

Parameters:

  • ctx: Request scope for the write.
  • job: The render to persist.

Returns:

  • err: Non-nil when the row cannot be written.

func (*DB) SaveClipProfile

func (db *DB) SaveClipProfile(ctx context.Context, profile ClipProfile) error

SaveClipProfile inserts or replaces a clip profile.

Parameters:

  • ctx: Request scope for the write.
  • profile: The clip profile to persist.

Returns:

  • err: Non-nil when the row cannot be written or the default cannot be assigned.

func (*DB) SaveSelectedServer

func (db *DB) SaveSelectedServer(ctx context.Context, server plex.Server) error

SaveSelectedServer upserts the single selected Plex server.

Parameters:

  • ctx: Request scope for the write.
  • server: The Plex server the user selected.

Returns:

  • err: Non-nil when the row cannot be written.

func (*DB) SaveToken

func (db *DB) SaveToken(ctx context.Context, clientID, accessToken string) error

SaveToken stores the Plex access token for a client ID.

Parameters:

  • ctx: Request scope for the write.
  • clientID: Identifier the token was issued to.
  • accessToken: The Plex access token to persist.

Returns:

  • err: Non-nil when the row cannot be written.

func (*DB) SelectedServer

func (db *DB) SelectedServer(ctx context.Context) (plex.Server, bool, error)

SelectedServer loads the persisted Plex server, if any.

Parameters:

  • ctx: Request scope for the read.

Returns:

  • server: The stored server, or the zero value when none is stored.
  • found: True when a server row was present.
  • err: Non-nil when the read fails.

func (*DB) SetDefaultClipProfile

func (db *DB) SetDefaultClipProfile(ctx context.Context, id string) error

SetDefaultClipProfile marks one profile as the default.

Parameters:

  • ctx: Request scope for the write.
  • id: Identifier of the profile to mark.

Returns:

  • err: Non-nil when the profile is unknown or the flag cannot be assigned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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