2018-11-06 19:02:03 +01:00
|
|
|
/*
|
|
|
|
This package contains models for data storage based on GORM.
|
|
|
|
|
|
|
|
See http://gorm.io/docs/ for more information about GORM.
|
|
|
|
|
|
|
|
Additional information concerning data storage can be found in our Developer Guide:
|
|
|
|
|
|
|
|
https://github.com/photoprism/photoprism/wiki/Storage
|
|
|
|
*/
|
2019-12-11 16:55:18 +01:00
|
|
|
package entity
|
2019-12-11 19:11:44 +01:00
|
|
|
|
|
|
|
import (
|
2019-12-27 05:18:52 +01:00
|
|
|
"strconv"
|
2020-01-06 04:24:49 +01:00
|
|
|
"sync"
|
2019-12-27 05:18:52 +01:00
|
|
|
"time"
|
|
|
|
|
2019-12-11 19:11:44 +01:00
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/photoprism/photoprism/internal/event"
|
2020-01-06 14:32:15 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/rnd"
|
2019-12-11 19:11:44 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = event.Log
|
2020-01-06 04:24:49 +01:00
|
|
|
var writeMutex = sync.Mutex{}
|
2019-12-11 19:11:44 +01:00
|
|
|
|
|
|
|
func logError(result *gorm.DB) {
|
|
|
|
if result.Error != nil {
|
|
|
|
log.Error(result.Error.Error())
|
|
|
|
}
|
|
|
|
}
|
2019-12-27 05:18:52 +01:00
|
|
|
|
|
|
|
func ID(prefix rune) string {
|
|
|
|
result := make([]byte, 0, 17)
|
|
|
|
result = append(result, byte(prefix))
|
|
|
|
result = append(result, strconv.FormatInt(time.Now().UTC().Unix(), 36)[0:6]...)
|
2020-01-06 14:32:15 +01:00
|
|
|
result = append(result, rnd.Token(10)...)
|
2019-12-27 05:18:52 +01:00
|
|
|
|
|
|
|
return string(result)
|
|
|
|
}
|