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
- Variables
- func AccountByID(id uint) (result entity.Service, err error)
- func AccountUploads(a entity.Service, limit int) (results entity.Files, err error)
- func AlbumByUID(albumUID string) (album entity.Album, err error)
- func AlbumCoverByUID(uid string, public bool) (file entity.File, err error)
- func AlbumEntryFound(uid string) error
- func AlbumFolders(threshold int) (folders entity.Folders, err error)
- func Albums(offset, limit int) (results entity.Albums, err error)
- func AlbumsPhotoUIDs(albums []string, includeDefault, includePrivate bool) (photos []string, err error)
- func ArchivedPhotos(limit int, offset int) (entities entity.Photos, err error)
- func BatchSize() int
- func Clients(limit, offset int, sortOrder, search string) (result entity.Clients, err error)
- func CountFileHashes() (count int)
- func CountMarkers(markerType string) (n int)
- func CountNewFaceMarkers(size, score int) (n int)
- func CountUnmatchedFaceMarkers() (n int)
- func CreateMarkerSubjects() (affected int64, err error)
- func Db() *gorm.DB
- func DbDialect() string
- func DeleteErrors() (err error)
- func Duplicates(limit, offset int, pathName string) (files entity.Duplicates, err error)
- func Embeddings(single, unclustered bool, size, score int) (result face.Embeddings, err error)
- func Errors(limit, offset int, search string) (results entity.Errors, err error)
- func ExpiredFileShares(account entity.Service) (result []entity.FileShare, err error)
- func FaceMarkers(limit, offset int) (result entity.Markers, err error)
- func Faces(knownOnly, unmatchedOnly, hidden, ignored bool) (result entity.Faces, err error)
- func FacesByID(knownOnly, unmatchedOnly, hidden, ignored bool) (FaceMap, IDs, error)
- func FetchHashMap(rows *sql.Rows, result HashMap, hashLen int) (err error)
- func FileByHash(fileHash string) (*entity.File, error)
- func FileByPhotoUID(photoUID string) (*entity.File, error)
- func FileByUID(fileUID string) (*entity.File, error)
- func FileShares(accountId uint, status string) (result []entity.FileShare, err error)
- func FileSyncs(accountId uint, status string, limit int) (result []entity.FileSync, err error)
- func Files(limit, offset int, pathName string, includeMissing bool) (files entity.Files, err error)
- func FilesByPath(limit, offset int, rootName, pathName string, public bool) (files entity.Files, err error)
- func FilesByUID(u []string, limit int, offset int) (files entity.Files, err error)
- func FixMarkerReferences() (removed int64, err error)
- func FixPrimaries() error
- func FlagHiddenPhotos() (err error)
- func FolderCoverByUID(uid string) (file entity.File, err error)
- func FoldersByPath(rootName, rootPath, path string, recursive bool) (folders entity.Folders, err error)
- func LabelBySlug(labelSlug string) (label entity.Label, err error)
- func LabelByUID(labelUID string) (label entity.Label, err error)
- func LabelThumbBySlug(labelSlug string) (file entity.File, err error)
- func LabelThumbByUID(labelUID string) (file entity.File, err error)
- func ManuallyAddedFaces(hidden, ignored bool) (result entity.Faces, err error)
- func MarkerByUID(uid string) (*entity.Marker, error)
- func Markers(limit, offset int, markerType string, embeddings, subjects bool, ...) (result entity.Markers, err error)
- func MarkersWithNonExistentReferences() (faces entity.Markers, subjects entity.Markers, err error)
- func MarkersWithSubjectConflict() (results entity.Markers, err error)
- func MatchFaceMarkers() (affected int64, err error)
- func MergeFaces(merge entity.Faces, ignored bool) (merged *entity.Face, err error)
- func MissingPhotos(limit int, offset int) (entities entity.Photos, err error)
- func MomentLabelsFilter(label string) string
- func OrphanFiles() (files entity.Files, err error)
- func OrphanPhotos() (photos entity.Photos, err error)
- func People() (people entity.People, err error)
- func PeopleCount() (count int, err error)
- func PhotoByID(photoID uint64) (photo entity.Photo, err error)
- func PhotoByUID(photoUID string) (photo entity.Photo, err error)
- func PhotoLabel(photoID, labelID uint) (label entity.PhotoLabel, err error)
- func PhotoPreloadByUID(photoUID string) (photo entity.Photo, err error)
- func PhotosMetadataUpdate(limit, offset int, delay, interval time.Duration) (entities entity.Photos, err error)
- func PurgeOrphanCameras() error
- func PurgeOrphanCountries() error
- func PurgeOrphanDuplicates() error
- func PurgeOrphanFaces(faceIds []string, ignored bool) (affected int, err error)
- func PurgeOrphanFiles() (count int, err error)
- func PurgeOrphanLenses() error
- func PurgeOrphans() error
- func PurgePlaces() error
- func RegisteredUsers() (result entity.Users)
- func RemoveAnonymousFaceClusters() (removed int, err error)
- func RemoveAutoFaceClusters() (removed int, err error)
- func RemoveDuplicateMoments() (removed int, err error)
- func RemoveInvalidMarkerReferences() (removed int64, err error)
- func RemoveNonExistentMarkerFaces() (removed int64, err error)
- func RemoveNonExistentMarkerSubjects() (removed int64, err error)
- func RemoveOrphanMarkers() (removed int64, err error)
- func RemoveOrphanSubjects() (removed int64, err error)
- func RemovePeopleAndFaces() (err error)
- func RenameFile(srcRoot, srcName, destRoot, destName string) error
- func ResetFaceMarkerMatches() (removed int64, err error)
- func ResolveFaceCollisions() (conflicts, resolved int, err error)
- func SelectedFiles(f form.Selection, o FileSelection) (results entity.Files, err error)
- func SelectedPhotos(f form.Selection) (results entity.Photos, err error)
- func Session(id string) (result entity.Session, err error)
- func Sessions(limit, offset int, sortOrder, search string) (result entity.Sessions, err error)
- func SetDownloadFileID(filename string, fileId uint) error
- func SetFileError(fileUID, errorString string)
- func SetPhotoPrimary(photoUID, fileUID string) (err error)
- func SubjectMap() (result map[string]entity.Subject, err error)
- func Subjects(limit, offset int) (result entity.Subjects, err error)
- func UnmatchedFaceMarkers(limit, offset int, matchedBefore *time.Time) (result entity.Markers, err error)
- func UnscopedDb() *gorm.DB
- func UpdateAlbumCovers() (err error)
- func UpdateAlbumDates() error
- func UpdateAlbumDefaultCovers() (err error)
- func UpdateAlbumFolderCovers() (err error)
- func UpdateAlbumMonthCovers() (err error)
- func UpdateCovers() (err error)
- func UpdateFolderDates() error
- func UpdateLabelCovers() (err error)
- func UpdateMissingAlbumEntries() error
- func UpdateSubjectCovers() (err error)
- func Users(limit, offset int, sortOrder, search string) (result entity.Users, err error)
- func VideoByPhotoUID(photoUID string) (*entity.File, error)
- type CategoryLabel
- type Cell
- type Cells
- type Cols
- type Counts
- type FaceMap
- type FileMap
- type FileSelection
- type HashMap
- type IDs
- type Moment
- type Moments
- func MomentsCountries(threshold int, public bool) (results Moments, err error)
- func MomentsLabels(threshold int, public bool) (results Moments, err error)
- func MomentsStates(threshold int, public bool) (results Moments, err error)
- func MomentsTime(threshold int, public bool) (results Moments, err error)
- type PhotoMap
- type Query
- type SearchCount
Constants ¶
const ( MySQL = "mysql" SQLite3 = "sqlite3" )
const MegaByte = 1024 * 1024
Variables ¶
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 ¶
AccountByID finds an account by primary key.
func AccountUploads ¶
AccountUploads a list of files for uploading to a remote account.
func AlbumByUID ¶
AlbumByUID returns a Album based on the UID.
func AlbumCoverByUID ¶
AlbumCoverByUID returns an album cover file based on the uid.
func AlbumEntryFound ¶
AlbumEntryFound removes the missing flag from album entries.
func AlbumFolders ¶
AlbumFolders returns folders that should be added as album.
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 ¶
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 CountFileHashes ¶
func CountFileHashes() (count int)
CountFileHashes counts distinct file hashes.
func CountMarkers ¶
CountMarkers counts the number of face markers in the index.
func CountNewFaceMarkers ¶
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 ¶
CreateMarkerSubjects adds and references known marker subjects.
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 ExpiredFileShares ¶
ExpiredFileShares returns up to 100 expired file shares for a given account.
func FaceMarkers ¶
FaceMarkers returns all face markers sorted by id.
func FacesByID ¶
FacesByID retrieves faces from the database and returns a map with the Face ID as key.
func FetchHashMap ¶
FetchHashMap populates a hash map from the database.
func FileByHash ¶
FileByHash finds a file with a given hash string.
func FileByPhotoUID ¶
FileByPhotoUID finds a file for the given photo UID.
func FileShares ¶
FileShares returns up to 100 file shares for a given account id and status.
func Files ¶
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 ¶
FilesByUID finds files for the given UIDs.
func FixMarkerReferences ¶
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 ¶
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 ¶
LabelBySlug returns a Label based on the slug name.
func LabelByUID ¶
LabelByUID returns a Label based on the label UID.
func LabelThumbBySlug ¶
LabelThumbBySlug returns a label cover file based on the slug name.
func LabelThumbByUID ¶
LabelThumbByUID returns a label cover file based on the label UID.
func ManuallyAddedFaces ¶
ManuallyAddedFaces returns all manually added face clusters.
func MarkerByUID ¶
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 ¶
MarkersWithNonExistentReferences finds markers with non-existent face or subject references.
func MarkersWithSubjectConflict ¶
MarkersWithSubjectConflict finds markers with conflicting subjects.
func MatchFaceMarkers ¶
MatchFaceMarkers matches markers with known faces.
func MergeFaces ¶
MergeFaces returns a new face that replaces multiple others.
func MissingPhotos ¶
MissingPhotos returns photo entities without existing files.
func MomentLabelsFilter ¶
MomentLabelsFilter returns the smart filter string for a moment based on a matching label.
func OrphanFiles ¶
OrphanFiles finds files without a photo.
func OrphanPhotos ¶
OrphanPhotos finds orphan index entries that may be removed.
func PeopleCount ¶
PeopleCount returns the total number of people in the index.
func PhotoByUID ¶
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 ¶
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 ¶
PurgeOrphanFaces removes unused faces from the index.
func PurgeOrphanFiles ¶
PurgeOrphanFiles removes files without a photo from the index.
func PurgeOrphanLenses ¶
func PurgeOrphanLenses() error
PurgeOrphanLenses removes cameras without any photos.
func PurgePlaces ¶
func PurgePlaces() error
PurgePlaces removes unused entries from the places table.
func RegisteredUsers ¶
RegisteredUsers finds all registered users.
func RemoveAnonymousFaceClusters ¶
RemoveAnonymousFaceClusters removes anonymous faces from the index.
func RemoveAutoFaceClusters ¶
RemoveAutoFaceClusters removes automatically added face clusters from the index.
func RemoveDuplicateMoments ¶
RemoveDuplicateMoments deletes generated albums with duplicate slug or filter.
func RemoveInvalidMarkerReferences ¶
RemoveInvalidMarkerReferences removes face and subject references from invalid markers.
func RemoveNonExistentMarkerFaces ¶
RemoveNonExistentMarkerFaces removes non-existent face IDs from the markers table.
func RemoveNonExistentMarkerSubjects ¶
RemoveNonExistentMarkerSubjects removes non-existent subject UIDs from the markers table.
func RemoveOrphanMarkers ¶
RemoveOrphanMarkers removes markers without an existing file.
func RemoveOrphanSubjects ¶
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 ¶
RenameFile renames an indexed file.
func ResetFaceMarkerMatches ¶
ResetFaceMarkerMatches removes automatically added subject and face references from the markers table.
func ResolveFaceCollisions ¶
ResolveFaceCollisions resolves collisions of different subject's faces.
func SelectedFiles ¶
SelectedFiles finds files based on the given selection form, e.g. for downloading or sharing.
func SelectedPhotos ¶
SelectedPhotos finds photos based on the given selection form, e.g. for adding them to an album.
func SetDownloadFileID ¶
SetDownloadFileID updates the local file id for remote downloads.
func SetFileError ¶
func SetFileError(fileUID, errorString string)
SetFileError updates the file error column.
func SetPhotoPrimary ¶
SetPhotoPrimary sets a new primary image file for a photo.
func SubjectMap ¶
SubjectMap returns a map of subjects indexed by UID.
func UnmatchedFaceMarkers ¶
func UnmatchedFaceMarkers(limit, offset int, matchedBefore *time.Time) (result entity.Markers, err error)
UnmatchedFaceMarkers finds all currently unmatched face markers.
func UnscopedDb ¶
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.
Types ¶
type CategoryLabel ¶
func CategoryLabels ¶
func CategoryLabels(limit, offset int) (results []CategoryLabel)
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"` }
type FileMap ¶
func IndexedFiles ¶
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 ¶
func FileHashMap ¶
FileHashMap returns a map of all known file hashes.
func ThumbHashMap ¶
ThumbHashMap returns a map of all known thumb file hashes.
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 ¶
CountryName returns the country name if any.
type Moments ¶
type Moments []Moment
Moments represents a list of moments.
func MomentsCountries ¶
MomentsCountries returns the most popular countries by year.
func MomentsLabels ¶
MomentsLabels returns the most popular photo labels.
func MomentsStates ¶
MomentsStates returns the most popular states and countries by year.
type PhotoMap ¶
func IndexedPhotos ¶
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.
type SearchCount ¶
type SearchCount struct {
Total int
}
SearchCount is the total number of search hits.
Source Files ¶
- account.go
- account_uploads.go
- albums.go
- categories.go
- clients.go
- counts.go
- covers.go
- duplicates.go
- errors.go
- faces.go
- file_selection.go
- file_shares.go
- file_sync_download.go
- file_syncs.go
- files.go
- files_hashes.go
- folders.go
- label.go
- markers.go
- moments.go
- photo.go
- photo_map.go
- photo_selection.go
- places.go
- purge.go
- query.go
- sessions.go
- subjects.go
- users.go