query

package
v0.0.0-...-2f5502e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package query provides frequently used database queries for use in commands and API.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const (
	MySQL   = "mysql"
	SQLite3 = "sqlite3"
)
View Source
const MegaByte = 1024 * 1024

Variables

View Source
var MomentLabels = map[string]string{
	"park":             "Parks & Gardens",
	"botanical-garden": "Parks & Gardens",
	"water-park":       "Parks & Gardens",
	"alpine":           "Outdoor Adventures",
	"hiking":           "Outdoor Adventures",
	"mountain":         "Outdoor Adventures",
	"mountains":        "Outdoor Adventures",
	"camping":          "Outdoor Adventures",
	"camper":           "Outdoor Adventures",
	"bench":            "Outdoor Adventures",
	"bunker":           "Outdoor Adventures",
	"castle":           "Outdoor Adventures",
	"viewpoint":        "Outdoor Adventures",
	"nature-reserve":   "Nature & Landscape",
	"landscape":        "Nature & Landscape",
	"nature":           "Nature & Landscape",
	"flower":           "Nature & Landscape",
	"field":            "Nature & Landscape",
	"forest":           "Nature & Landscape",
	"rocks":            "Nature & Landscape",
	"valley":           "Nature & Landscape",
	"bay":              "Bays, Capes & Beaches",
	"beach":            "Bays, Capes & Beaches",
	"seashore":         "Bays, Capes & Beaches",
	"cape":             "Bays, Capes & Beaches",
	"ship":             "Water, Ships & Boats",
	"water":            "Water, Ships & Boats",
	"pier":             "Water, Ships & Boats",
	"boat":             "Water, Ships & Boats",
	"boathouse":        "Water, Ships & Boats",
	"lakeside":         "Water, Ships & Boats",
	"shark":            "Water, Ships & Boats",
	"fish":             "Water, Ships & Boats",
	"jellyfish":        "Water, Ships & Boats",
	"submarine":        "Water, Ships & Boats",
	"diving":           "Water, Ships & Boats",
	"festival":         "Festivals & Entertainment",
	"nightclub":        "Festivals & Entertainment",
	"microphone":       "Festivals & Entertainment",
	"stage":            "Festivals & Entertainment",
	"theater":          "Festivals & Entertainment",
	"theme park":       "Festivals & Entertainment",
	"event":            "Festivals & Entertainment",
	"wine":             "Festivals & Entertainment",
	"easter":           "Holidays",
	"thanksgiving":     "Holidays",
	"christmas":        "Holidays",
	"passover":         "Holidays",
	"shavuot":          "Holidays",
	"hanukkah":         "Holidays",
	"cat":              "Pets",
	"dog":              "Pets",
	"gerbil":           "Pets",
	"parakeet":         "Pets",
	"rabbit":           "Pets",
	"hamster":          "Pets",
}

Functions

func AccountByID

func AccountByID(id uint) (result entity.Service, err error)

AccountByID finds an account by primary key.

func AccountUploads

func AccountUploads(a entity.Service, limit int) (results entity.Files, err error)

AccountUploads a list of files for uploading to a remote account.

func AlbumByUID

func AlbumByUID(albumUID string) (album entity.Album, err error)

AlbumByUID returns a Album based on the UID.

func AlbumCoverByUID

func AlbumCoverByUID(uid string, public bool) (file entity.File, err error)

AlbumCoverByUID returns an album cover file based on the uid.

func AlbumEntryFound

func AlbumEntryFound(uid string) error

AlbumEntryFound removes the missing flag from album entries.

func AlbumFolders

func AlbumFolders(threshold int) (folders entity.Folders, err error)

AlbumFolders returns folders that should be added as album.

func Albums

func Albums(offset, limit int) (results entity.Albums, err error)

Albums returns a slice of albums.

func AlbumsPhotoUIDs

func AlbumsPhotoUIDs(albums []string, includeDefault, includePrivate bool) (photos []string, err error)

AlbumsPhotoUIDs returns up to 100000 photo UIDs that belong to the specified albums.

func ArchivedPhotos

func ArchivedPhotos(limit int, offset int) (entities entity.Photos, err error)

ArchivedPhotos finds and returns archived photos.

func BatchSize

func BatchSize() int

BatchSize returns the maximum query parameter number based on the current sql database dialect.

func Clients

func Clients(limit, offset int, sortOrder, search string) (result entity.Clients, err error)

Clients finds clients and returns them.

func CountFileHashes

func CountFileHashes() (count int)

CountFileHashes counts distinct file hashes.

func CountMarkers

func CountMarkers(markerType string) (n int)

CountMarkers counts the number of face markers in the index.

func CountNewFaceMarkers

func CountNewFaceMarkers(size, score int) (n int)

CountNewFaceMarkers counts the number of new face markers in the index.

func CountUnmatchedFaceMarkers

func CountUnmatchedFaceMarkers() (n int)

CountUnmatchedFaceMarkers counts the number of unmatched face markers in the index.

func CreateMarkerSubjects

func CreateMarkerSubjects() (affected int64, err error)

CreateMarkerSubjects adds and references known marker subjects.

func Db

func Db() *gorm.DB

Db returns a database connection instance.

func DbDialect

func DbDialect() string

DbDialect returns the sql database dialect name.

func DeleteErrors

func DeleteErrors() (err error)

DeleteErrors removes all entries from the errors table.

func Duplicates

func Duplicates(limit, offset int, pathName string) (files entity.Duplicates, err error)

Duplicates finds duplicate files in the range of limit and offset sorted by file name.

func Embeddings

func Embeddings(single, unclustered bool, size, score int) (result face.Embeddings, err error)

Embeddings returns existing face embeddings.

func Errors

func Errors(limit, offset int, search string) (results entity.Errors, err error)

Errors returns the error log filtered with an optional search string.

func ExpiredFileShares

func ExpiredFileShares(account entity.Service) (result []entity.FileShare, err error)

ExpiredFileShares returns up to 100 expired file shares for a given account.

func FaceMarkers

func FaceMarkers(limit, offset int) (result entity.Markers, err error)

FaceMarkers returns all face markers sorted by id.

func Faces

func Faces(knownOnly, unmatchedOnly, hidden, ignored bool) (result entity.Faces, err error)

Faces returns all (known / unmatched) faces from the index.

func FacesByID

func FacesByID(knownOnly, unmatchedOnly, hidden, ignored bool) (FaceMap, IDs, error)

FacesByID retrieves faces from the database and returns a map with the Face ID as key.

func FetchHashMap

func FetchHashMap(rows *sql.Rows, result HashMap, hashLen int) (err error)

FetchHashMap populates a hash map from the database.

func FileByHash

func FileByHash(fileHash string) (*entity.File, error)

FileByHash finds a file with a given hash string.

func FileByPhotoUID

func FileByPhotoUID(photoUID string) (*entity.File, error)

FileByPhotoUID finds a file for the given photo UID.

func FileByUID

func FileByUID(fileUID string) (*entity.File, error)

FileByUID finds a file entity for the given UID.

func FileShares

func FileShares(accountId uint, status string) (result []entity.FileShare, err error)

FileShares returns up to 100 file shares for a given account id and status.

func FileSyncs

func FileSyncs(accountId uint, status string, limit int) (result []entity.FileSync, err error)

FileSyncs returns a list of FileSync entities for a given account and status.

func Files

func Files(limit, offset int, pathName string, includeMissing bool) (files entity.Files, err error)

Files returns not-missing and not-deleted file entities in the range of limit and offset sorted by id.

func FilesByPath

func FilesByPath(limit, offset int, rootName, pathName string, public bool) (files entity.Files, err error)

FilesByPath returns a slice of files in a given originals folder.

func FilesByUID

func FilesByUID(u []string, limit int, offset int) (files entity.Files, err error)

FilesByUID finds files for the given UIDs.

func FixMarkerReferences

func FixMarkerReferences() (removed int64, err error)

FixMarkerReferences repairs invalid or non-existent references in the markers table.

func FixPrimaries

func FixPrimaries() error

FixPrimaries tries to set a primary file for photos that have none.

func FlagHiddenPhotos

func FlagHiddenPhotos() (err error)

FlagHiddenPhotos sets the quality score of photos without valid primary file to -1.

func FolderCoverByUID

func FolderCoverByUID(uid string) (file entity.File, err error)

FolderCoverByUID returns a folder cover file based on the uid.

func FoldersByPath

func FoldersByPath(rootName, rootPath, path string, recursive bool) (folders entity.Folders, err error)

FoldersByPath returns a slice of folders in a given directory incl subfolders in recursive mode.

func LabelBySlug

func LabelBySlug(labelSlug string) (label entity.Label, err error)

LabelBySlug returns a Label based on the slug name.

func LabelByUID

func LabelByUID(labelUID string) (label entity.Label, err error)

LabelByUID returns a Label based on the label UID.

func LabelThumbBySlug

func LabelThumbBySlug(labelSlug string) (file entity.File, err error)

LabelThumbBySlug returns a label cover file based on the slug name.

func LabelThumbByUID

func LabelThumbByUID(labelUID string) (file entity.File, err error)

LabelThumbByUID returns a label cover file based on the label UID.

func ManuallyAddedFaces

func ManuallyAddedFaces(hidden, ignored bool) (result entity.Faces, err error)

ManuallyAddedFaces returns all manually added face clusters.

func MarkerByUID

func MarkerByUID(uid string) (*entity.Marker, error)

MarkerByUID returns a Marker based on the UID.

func Markers

func Markers(limit, offset int, markerType string, embeddings, subjects bool, matchedBefore time.Time) (result entity.Markers, err error)

Markers finds a list of file markers filtered by type, embeddings, and sorted by id.

func MarkersWithNonExistentReferences

func MarkersWithNonExistentReferences() (faces entity.Markers, subjects entity.Markers, err error)

MarkersWithNonExistentReferences finds markers with non-existent face or subject references.

func MarkersWithSubjectConflict

func MarkersWithSubjectConflict() (results entity.Markers, err error)

MarkersWithSubjectConflict finds markers with conflicting subjects.

func MatchFaceMarkers

func MatchFaceMarkers() (affected int64, err error)

MatchFaceMarkers matches markers with known faces.

func MergeFaces

func MergeFaces(merge entity.Faces, ignored bool) (merged *entity.Face, err error)

MergeFaces returns a new face that replaces multiple others.

func MissingPhotos

func MissingPhotos(limit int, offset int) (entities entity.Photos, err error)

MissingPhotos returns photo entities without existing files.

func MomentLabelsFilter

func MomentLabelsFilter(label string) string

MomentLabelsFilter returns the smart filter string for a moment based on a matching label.

func OrphanFiles

func OrphanFiles() (files entity.Files, err error)

OrphanFiles finds files without a photo.

func OrphanPhotos

func OrphanPhotos() (photos entity.Photos, err error)

OrphanPhotos finds orphan index entries that may be removed.

func People

func People() (people entity.People, err error)

People returns the sorted names of the first 2000 people.

func PeopleCount

func PeopleCount() (count int, err error)

PeopleCount returns the total number of people in the index.

func PhotoByID

func PhotoByID(photoID uint64) (photo entity.Photo, err error)

PhotoByID returns a Photo based on the ID.

func PhotoByUID

func PhotoByUID(photoUID string) (photo entity.Photo, err error)

PhotoByUID returns a Photo based on the UID.

func PhotoLabel

func PhotoLabel(photoID, labelID uint) (label entity.PhotoLabel, err error)

PhotoLabel returns a photo label entity if exists.

func PhotoPreloadByUID

func PhotoPreloadByUID(photoUID string) (photo entity.Photo, err error)

PhotoPreloadByUID returns a Photo based on the UID with all dependencies preloaded.

func PhotosMetadataUpdate

func PhotosMetadataUpdate(limit, offset int, delay, interval time.Duration) (entities entity.Photos, err error)

PhotosMetadataUpdate returns photos selected for metadata maintenance.

func PurgeOrphanCameras

func PurgeOrphanCameras() error

PurgeOrphanCameras removes cameras without any photos.

func PurgeOrphanCountries

func PurgeOrphanCountries() error

PurgeOrphanCountries removes countries without any photos.

func PurgeOrphanDuplicates

func PurgeOrphanDuplicates() error

PurgeOrphanDuplicates deletes all files from the duplicates table that don't exist in the files table.

func PurgeOrphanFaces

func PurgeOrphanFaces(faceIds []string, ignored bool) (affected int, err error)

PurgeOrphanFaces removes unused faces from the index.

func PurgeOrphanFiles

func PurgeOrphanFiles() (count int, err error)

PurgeOrphanFiles removes files without a photo from the index.

func PurgeOrphanLenses

func PurgeOrphanLenses() error

PurgeOrphanLenses removes cameras without any photos.

func PurgeOrphans

func PurgeOrphans() error

PurgeOrphans removes orphan database entries.

func PurgePlaces

func PurgePlaces() error

PurgePlaces removes unused entries from the places table.

func RegisteredUsers

func RegisteredUsers() (result entity.Users)

RegisteredUsers finds all registered users.

func RemoveAnonymousFaceClusters

func RemoveAnonymousFaceClusters() (removed int, err error)

RemoveAnonymousFaceClusters removes anonymous faces from the index.

func RemoveAutoFaceClusters

func RemoveAutoFaceClusters() (removed int, err error)

RemoveAutoFaceClusters removes automatically added face clusters from the index.

func RemoveDuplicateMoments

func RemoveDuplicateMoments() (removed int, err error)

RemoveDuplicateMoments deletes generated albums with duplicate slug or filter.

func RemoveInvalidMarkerReferences

func RemoveInvalidMarkerReferences() (removed int64, err error)

RemoveInvalidMarkerReferences removes face and subject references from invalid markers.

func RemoveNonExistentMarkerFaces

func RemoveNonExistentMarkerFaces() (removed int64, err error)

RemoveNonExistentMarkerFaces removes non-existent face IDs from the markers table.

func RemoveNonExistentMarkerSubjects

func RemoveNonExistentMarkerSubjects() (removed int64, err error)

RemoveNonExistentMarkerSubjects removes non-existent subject UIDs from the markers table.

func RemoveOrphanMarkers

func RemoveOrphanMarkers() (removed int64, err error)

RemoveOrphanMarkers removes markers without an existing file.

func RemoveOrphanSubjects

func RemoveOrphanSubjects() (removed int64, err error)

RemoveOrphanSubjects permanently removes dangling marker subjects from the index.

func RemovePeopleAndFaces

func RemovePeopleAndFaces() (err error)

RemovePeopleAndFaces permanently removes all people, faces, and face markers.

func RenameFile

func RenameFile(srcRoot, srcName, destRoot, destName string) error

RenameFile renames an indexed file.

func ResetFaceMarkerMatches

func ResetFaceMarkerMatches() (removed int64, err error)

ResetFaceMarkerMatches removes automatically added subject and face references from the markers table.

func ResolveFaceCollisions

func ResolveFaceCollisions() (conflicts, resolved int, err error)

ResolveFaceCollisions resolves collisions of different subject's faces.

func SelectedFiles

func SelectedFiles(f form.Selection, o FileSelection) (results entity.Files, err error)

SelectedFiles finds files based on the given selection form, e.g. for downloading or sharing.

func SelectedPhotos

func SelectedPhotos(f form.Selection) (results entity.Photos, err error)

SelectedPhotos finds photos based on the given selection form, e.g. for adding them to an album.

func Session

func Session(id string) (result entity.Session, err error)

Session finds an existing session by its id.

func Sessions

func Sessions(limit, offset int, sortOrder, search string) (result entity.Sessions, err error)

Sessions finds user sessions and returns them.

func SetDownloadFileID

func SetDownloadFileID(filename string, fileId uint) error

SetDownloadFileID updates the local file id for remote downloads.

func SetFileError

func SetFileError(fileUID, errorString string)

SetFileError updates the file error column.

func SetPhotoPrimary

func SetPhotoPrimary(photoUID, fileUID string) (err error)

SetPhotoPrimary sets a new primary image file for a photo.

func SubjectMap

func SubjectMap() (result map[string]entity.Subject, err error)

SubjectMap returns a map of subjects indexed by UID.

func Subjects

func Subjects(limit, offset int) (result entity.Subjects, err error)

Subjects returns subjects from the index.

func UnmatchedFaceMarkers

func UnmatchedFaceMarkers(limit, offset int, matchedBefore *time.Time) (result entity.Markers, err error)

UnmatchedFaceMarkers finds all currently unmatched face markers.

func UnscopedDb

func UnscopedDb() *gorm.DB

UnscopedDb returns an unscoped database connection instance.

func UpdateAlbumCovers

func UpdateAlbumCovers() (err error)

UpdateAlbumCovers updates album cover thumbs.

func UpdateAlbumDates

func UpdateAlbumDates() error

UpdateAlbumDates updates the year, month and day of the album based on the indexed photo metadata.

func UpdateAlbumDefaultCovers

func UpdateAlbumDefaultCovers() (err error)

UpdateAlbumDefaultCovers updates default album cover thumbs.

func UpdateAlbumFolderCovers

func UpdateAlbumFolderCovers() (err error)

UpdateAlbumFolderCovers updates folder album cover thumbs.

func UpdateAlbumMonthCovers

func UpdateAlbumMonthCovers() (err error)

UpdateAlbumMonthCovers updates month album cover thumbs.

func UpdateCovers

func UpdateCovers() (err error)

UpdateCovers updates album, subject, and label cover thumbs.

func UpdateFolderDates

func UpdateFolderDates() error

UpdateFolderDates updates the year, month and day of the folder based on the indexed photo metadata.

func UpdateLabelCovers

func UpdateLabelCovers() (err error)

UpdateLabelCovers updates label cover thumbs.

func UpdateMissingAlbumEntries

func UpdateMissingAlbumEntries() error

UpdateMissingAlbumEntries sets a flag for missing photo album entries.

func UpdateSubjectCovers

func UpdateSubjectCovers() (err error)

UpdateSubjectCovers updates subject cover thumbs.

func Users

func Users(limit, offset int, sortOrder, search string) (result entity.Users, err error)

Users finds users and returns them.

func VideoByPhotoUID

func VideoByPhotoUID(photoUID string) (*entity.File, error)

VideoByPhotoUID finds a video for the given photo UID.

Types

type CategoryLabel

type CategoryLabel struct {
	Name  string
	Title string
}

func CategoryLabels

func CategoryLabels(limit, offset int) (results []CategoryLabel)

type Cell

type Cell struct {
	ID      string
	PlaceID string
}

type Cells

type Cells []Cell

func CellIDs

func CellIDs() (result Cells, err error)

CellIDs returns all known S2 cell ids as Cell slice.

type Cols

type Cols []string

Cols represents a list of database columns.

type Counts

type Counts struct {
	Cameras        int `json:"cameras"`
	Lenses         int `json:"lenses"`
	Countries      int `json:"countries"`
	Photos         int `json:"photos"`
	Videos         int `json:"videos"`
	Hidden         int `json:"hidden"`
	Favorites      int `json:"favorites"`
	Private        int `json:"private"`
	Review         int `json:"review"`
	Stories        int `json:"stories"`
	Albums         int `json:"albums"`
	Folders        int `json:"folders"`
	Files          int `json:"files"`
	Moments        int `json:"moments"`
	Places         int `json:"places"`
	Labels         int `json:"labels"`
	LabelMaxPhotos int `json:"labelMaxPhotos"`
}

func (*Counts) Refresh

func (c *Counts) Refresh()

Refresh updates the counts.

type FaceMap

type FaceMap map[string]entity.Face

FaceMap maps identification strings to face entities.

type FileMap

type FileMap map[string]int64

func IndexedFiles

func IndexedFiles() (result FileMap, err error)

IndexedFiles returns a map of already indexed files with their mod time unix timestamp as value.

type FileSelection

type FileSelection struct {
	MaxSize   int
	Media     []string
	OmitMedia []string
	Types     []string
	OmitTypes []string
	Primary   bool
	Originals bool
	Hidden    bool
	Private   bool
	Archived  bool
}

FileSelection represents a selection filter to include/exclude certain files.

func DownloadSelection

func DownloadSelection(mediaRaw, mediaSidecar, originals bool) FileSelection

DownloadSelection selects files to download.

func ShareSelection

func ShareSelection(originals bool) FileSelection

ShareSelection selects files to share, for example for upload via WebDAV.

type HashMap

type HashMap map[string]bool

func FileHashMap

func FileHashMap() (result HashMap, err error)

FileHashMap returns a map of all known file hashes.

func ThumbHashMap

func ThumbHashMap() (result HashMap, err error)

ThumbHashMap returns a map of all known thumb file hashes.

type IDs

type IDs []string

IDs represents a list of identifier strings.

type Moment

type Moment struct {
	Label      string `json:"Label"`
	Year       int    `json:"Year"`
	Month      int    `json:"Month"`
	State      string `json:"State"`
	Country    string `json:"Country"`
	PhotoCount int    `json:"PhotoCount"`
}

Moment contains photo counts per month and year

func (Moment) CountryName

func (m Moment) CountryName() string

CountryName returns the country name if any.

func (Moment) Location

func (m Moment) Location() string

Location returns the location name for the moment.

func (Moment) Slug

func (m Moment) Slug() (s string)

Slug returns an identifier string for a moment.

func (Moment) Title

func (m Moment) Title() string

Title returns an english title for the moment.

func (Moment) TitleSlug

func (m Moment) TitleSlug() string

TitleSlug returns an identifier string based on the title.

type Moments

type Moments []Moment

Moments represents a list of moments.

func MomentsCountries

func MomentsCountries(threshold int, public bool) (results Moments, err error)

MomentsCountries returns the most popular countries by year.

func MomentsLabels

func MomentsLabels(threshold int, public bool) (results Moments, err error)

MomentsLabels returns the most popular photo labels.

func MomentsStates

func MomentsStates(threshold int, public bool) (results Moments, err error)

MomentsStates returns the most popular states and countries by year.

func MomentsTime

func MomentsTime(threshold int, public bool) (results Moments, err error)

MomentsTime counts photos by month and year.

type PhotoMap

type PhotoMap map[string]uint

func IndexedPhotos

func IndexedPhotos() (result PhotoMap, err error)

IndexedPhotos returns a map of already indexed files with their mod time unix timestamp as value.

type Query

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

Query searches given an originals path and a db instance.

func New

func New(db *gorm.DB) *Query

New returns a new Query type with a given path and db instance.

type SearchCount

type SearchCount struct {
	Total int
}

SearchCount is the total number of search hits.

Jump to

Keyboard shortcuts

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