store

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store is the single-source media repository: one implementation against *sql.DB plus a kernel Dialect, replacing the three per-driver copies. Placeholder rendering, RETURNING support, and duplicate detection come from the dialect; everything else (columns, scans, messages, guards) ports the SQLite implementation verbatim, which the moved test suite pins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaFile

type MediaFile struct {
	ID               int            `json:"id"`
	UserID           int            `json:"userId"`
	Filename         string         `json:"filename"`
	OriginalFilename string         `json:"originalFilename"`
	MimeType         string         `json:"mimeType"`
	FileSize         int64          `json:"fileSize"`
	Width            int            `json:"width"`
	Height           int            `json:"height"`
	AltText          string         `json:"altText"`
	IsWebP           bool           `json:"isWebp"`
	FilePath         string         `json:"filePath"`
	URL              string         `json:"url"`
	Hash             string         `json:"hash"`
	Variants         sql.NullString `json:"variants"`
	CreatedAt        time.Time      `json:"createdAt"`
	UpdatedAt        time.Time      `json:"updatedAt"`
}

MediaFile represents a media file in the database

type Repository

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

Repository implements mediadomain.Repository for every driver.

func New

func New(db *sql.DB, dialect kerneldatabase.Dialect) *Repository

New creates a repository on db speaking dialect. Dialect must be non-nil; the composition root resolves it from the driver registry.

func (*Repository) Count

func (r *Repository) Count(ctx context.Context, ownerID int, search string, since time.Time) (int, error)

Count returns the total number of media matching the given owner scope, filename query, and creation-time threshold (zero time means no date filter). ownerID > 0 counts only that user's media; 0 (the admin scope) counts all. It mirrors the WHERE clauses of the FindAll*ByCursor methods so a list's total always matches its rows.

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, media *mediadomain.Media) error

Create stores a new media file.

func (*Repository) DeleteByID

func (r *Repository) DeleteByID(ctx context.Context, id int) error

DeleteByID removes a media file by ID (admin path)

func (*Repository) DeleteByOwner

func (r *Repository) DeleteByOwner(ctx context.Context, id int, userID int) error

DeleteByOwner removes a media file owned by a specific user

func (*Repository) FindAllByCursor

func (r *Repository) FindAllByCursor(ctx context.Context, ownerID int, limit int, beforeID int) ([]*mediadomain.Media, error)

FindAllByCursor returns media in newest-first (id DESC) order using keyset pagination (beforeID <= 0 means first page; otherwise only rows with id < beforeID). ownerID > 0 scopes the list to that user's library; 0 (the admin scope) returns every user's media. Used by the browser admin media library. The SELECT column list + row scan are reused via mediaColumns/mediaFrom/scanMediaRows.

func (*Repository) FindAllByDateRangeByCursor

func (r *Repository) FindAllByDateRangeByCursor(
	ctx context.Context,
	ownerID int,
	since time.Time,
	limit int,
	beforeID int,
) ([]*mediadomain.Media, error)

FindAllByDateRangeByCursor returns media created since the given time in newest-first (id DESC) order using keyset pagination (beforeID <= 0 means first page). ownerID > 0 scopes the list to that user's library; 0 (the admin scope) returns every user's media.

func (*Repository) FindAllByFilenameAndDateRangeByCursor

func (r *Repository) FindAllByFilenameAndDateRangeByCursor(
	ctx context.Context,
	ownerID int,
	filename string,
	since time.Time,
	limit int,
	beforeID int,
) ([]*mediadomain.Media, error)

FindAllByFilenameAndDateRangeByCursor returns media matching a filename query and created since the given time in newest-first (id DESC) order using keyset pagination (beforeID <= 0 means first page). ownerID > 0 scopes the search to that user's library; 0 (the admin scope) searches every user's.

func (*Repository) FindAllByFilenameByCursor

func (r *Repository) FindAllByFilenameByCursor(
	ctx context.Context,
	ownerID int,
	filename string,
	limit int,
	beforeID int,
) ([]*mediadomain.Media, error)

FindAllByFilenameByCursor returns media matching a filename query in newest-first (id DESC) order using keyset pagination (beforeID <= 0 means first page). ownerID > 0 scopes the search to that user's library; 0 (the admin scope) searches every user's media.

func (*Repository) FindByHash

func (r *Repository) FindByHash(ctx context.Context, hash string) (*mediadomain.Media, error)

FindByHash retrieves a media file by its full hash.

func (*Repository) FindByHashPrefix

func (r *Repository) FindByHashPrefix(ctx context.Context, prefix string) (*mediadomain.Media, error)

FindByHashPrefix retrieves a media file whose hash starts with the given prefix. The prefix is LIKE-escaped with an explicit ESCAPE clause (unlike the legacy SQLite copy, which interpolated it raw): hex prefixes behave identically, while wildcard input matches literally instead of globbing. The clause matters on every driver — SQLite has no default escape character, so without it the backslash escapes would be inert there.

func (*Repository) FindByID

func (r *Repository) FindByID(ctx context.Context, id int) (*mediadomain.Media, error)

FindByID retrieves a media file by ID with uploader name

func (*Repository) ListByCursor

func (r *Repository) ListByCursor(ctx context.Context, userID int, limit int, beforeID int) ([]*mediadomain.Media, error)

ListByCursor returns the caller's media in newest-first (id DESC) order using keyset pagination (beforeID <= 0 means first page; otherwise only rows with id < beforeID). The SELECT column list + row scan are reused via mediaColumns/mediaFrom/scanMediaRows.

func (*Repository) UpdateFileSize added in v1.1.3

func (r *Repository) UpdateFileSize(ctx context.Context, id int, size int64) error

UpdateFileSize refreshes the stored file size after an in-place rewrite.

Jump to

Keyboard shortcuts

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