Documentation
¶
Overview ¶
Package database provides SQLite and Postgres-protocol access for outtake.
Index ¶
- Constants
- Variables
- type ClipProfile
- type DB
- func (db *DB) ClearAuth(ctx context.Context) error
- func (db *DB) Close() error
- func (db *DB) Conn() *sql.DB
- func (db *DB) DefaultClipProfile(ctx context.Context) (ClipProfile, error)
- func (db *DB) DeleteClip(ctx context.Context, id string) error
- func (db *DB) DeleteClipProfile(ctx context.Context, id string) error
- func (db *DB) GetClip(ctx context.Context, id string) (*clip.Job, error)
- func (db *DB) GetClipProfile(ctx context.Context, id string) (ClipProfile, error)
- func (db *DB) LatestToken(ctx context.Context) (string, error)
- func (db *DB) ListClipProfiles(ctx context.Context) ([]ClipProfile, error)
- func (db *DB) ListClips(ctx context.Context) ([]*clip.Job, error)
- func (db *DB) ListClipsForMedia(ctx context.Context, mediaID string) ([]*clip.Job, error)
- func (db *DB) ListPendingClips(ctx context.Context) ([]*clip.Job, error)
- func (db *DB) SaveClip(ctx context.Context, job *clip.Job) error
- func (db *DB) SaveClipProfile(ctx context.Context, profile ClipProfile) error
- func (db *DB) SaveSelectedServer(ctx context.Context, server plex.Server) error
- func (db *DB) SaveToken(ctx context.Context, clientID, accessToken string) error
- func (db *DB) SelectedServer(ctx context.Context) (plex.Server, bool, error)
- func (db *DB) SetDefaultClipProfile(ctx context.Context, id string) error
Constants ¶
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 ¶
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") )
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 ¶
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 ¶
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 ¶
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 ¶
Close closes the database connection.
Returns:
- err: Non-nil when the connection cannot be closed.
func (*DB) Conn ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.