Documentation
¶
Overview ¶
Package db provides SQLite database operations for image metadata.
Index ¶
- func DefaultDBPath() string
- type DB
- func (db *DB) Close() error
- func (db *DB) Delete(filename string) error
- func (db *DB) EnsureImage(filename string, created, updated time.Time) error
- func (db *DB) GetAll() ([]*Image, error)
- func (db *DB) GetByFilename(filename string) (*Image, error)
- func (db *DB) IsProcessed(filename string) (bool, error)
- func (db *DB) RunMigrations() error
- func (db *DB) Search(query string) ([]*Image, error)
- func (db *DB) UpsertImage(img *Image) error
- type Image
- type StringSlice
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 (*DB) EnsureImage ¶
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) GetByFilename ¶
GetByFilename retrieves an image by filename.
func (*DB) IsProcessed ¶
IsProcessed checks if an image has been processed.
func (*DB) RunMigrations ¶
RunMigrations runs data migrations on the database.
func (*DB) Search ¶
Search searches for images by query string. Searches in words (JSON array), colors, filename, and file format.
func (*DB) UpsertImage ¶
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 ¶
FullRezURL returns the URL for a desktop-sized version via imgix.
func (*Image) MarshalJSON ¶
MarshalJSON implements custom JSON marshaling to include computed URL fields.
func (*Image) MergeMetadata ¶
MergeMetadata copies analysis metadata from another image (keeps original filename/dates).
func (*Image) ThumbnailURL ¶
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.