mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-21 01:06:10 +00:00
Run `go fix ./...` and keep mechanical modernization updates.
- Replace `interface{}` with `any` in signatures and local types
- Apply formatter/style cleanups from go1.26 tooling
- Keep `omitempty` behavior-preserving simplifications suggested by fix
- No functional feature changes intended
Validation:
- go test ./... -run '^$' -count=1 (Go 1.26.0)
- GOTOOLCHAIN=go1.24.10 go test ./... -run '^$' -count=1
Signed-off-by: Michael Mayer <michael@photoprism.app>
30 lines
623 B
Go
30 lines
623 B
Go
package entity
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
// Count returns the number of records for a given a model and key values.
|
|
func Count(m any, keys []string, values []any) int {
|
|
if m == nil || len(keys) != len(values) {
|
|
log.Debugf("entity: invalid parameters (count records)")
|
|
return -1
|
|
}
|
|
|
|
db, count := UnscopedDb(), 0
|
|
|
|
stmt := db.Model(m)
|
|
|
|
// Compose where condition.
|
|
for k := range keys {
|
|
stmt.Where("? = ?", gorm.Expr(keys[k]), values[k])
|
|
}
|
|
|
|
// Fetch count from database.
|
|
if err := stmt.Count(&count).Error; err != nil {
|
|
log.Debugf("entity: %s (count records)", err)
|
|
return -1
|
|
}
|
|
|
|
return count
|
|
}
|