db

package
v0.0.0-...-da64371 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package db provides SQLite database operations for image metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns the default path to the database file.

Types

type DB

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

DB wraps the GORM database connection.

func Open

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

Open opens or creates the SQLite database.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Delete

func (db *DB) Delete(filename string) error

Delete removes an image by filename.

func (*DB) EnsureImage

func (db *DB) EnsureImage(filename string, created, updated time.Time) error

EnsureImage creates a basic record for an image if it doesn't exist. Used to track images that exist in GCS but haven't been processed yet.

func (*DB) GetAll

func (db *DB) GetAll() ([]*Image, error)

GetAll retrieves all images.

func (*DB) GetByFilename

func (db *DB) GetByFilename(filename string) (*Image, error)

GetByFilename retrieves an image by filename.

func (*DB) IsProcessed

func (db *DB) IsProcessed(filename string) (bool, error)

IsProcessed checks if an image has been processed.

func (*DB) RunMigrations

func (db *DB) RunMigrations() error

RunMigrations runs data migrations on the database.

func (*DB) Search

func (db *DB) Search(query string) ([]*Image, error)

Search searches for images by query string. Searches in words (JSON array), colors, filename, and file format.

func (*DB) UpsertImage

func (db *DB) UpsertImage(img *Image) error

UpsertImage inserts or updates an image record.

type Image

type Image struct {
	ID           int64       `json:"id" gorm:"primaryKey;autoIncrement"`
	Filename     string      `json:"key" gorm:"uniqueIndex;not null"`
	DateAdded    time.Time   `json:"created_at" gorm:"autoCreateTime"`
	LastModified time.Time   `json:"updated_at"`
	Width        int         `json:"width,omitempty"`
	Height       int         `json:"height,omitempty"`
	PixelDensity float64     `json:"pixel_density,omitempty"`
	FileFormat   string      `json:"file_format,omitempty"`
	Colors       StringSlice `json:"colors,omitempty" gorm:"type:text"`
	Words        StringSlice `json:"words,omitempty" gorm:"type:text"`
	ProcessedAt  *time.Time  `json:"-"`
}

Image represents metadata for a wallpaper image.

func (*Image) FullRezURL

func (img *Image) FullRezURL() string

FullRezURL returns the URL for a desktop-sized version via imgix.

func (*Image) MarshalJSON

func (img *Image) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to include computed URL fields.

func (*Image) MergeMetadata

func (img *Image) MergeMetadata(other *Image)

MergeMetadata copies analysis metadata from another image (keeps original filename/dates).

func (*Image) RawURL

func (img *Image) RawURL() string

RawURL returns the direct URL to the original file in GCS.

func (Image) TableName

func (Image) TableName() string

TableName specifies the table name for the Image model.

func (*Image) ThumbnailURL

func (img *Image) ThumbnailURL() string

ThumbnailURL returns the URL for a small cropped thumbnail via imgix.

type StringSlice

type StringSlice []string

StringSlice is a custom type for storing []string as JSON in the database.

func (*StringSlice) Scan

func (s *StringSlice) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (StringSlice) Value

func (s StringSlice) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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