flightlesssomething/models.go
2024-07-04 23:29:32 +03:00

38 lines
802 B
Go

package flightlesssomething
import (
"github.com/dustin/go-humanize"
"gorm.io/gorm"
)
type User struct {
gorm.Model
DiscordID string
Username string
Benchmarks []Benchmark `gorm:"constraint:OnDelete:CASCADE;"`
}
type Benchmark struct {
gorm.Model
UserID uint
Title string
Description string
SpecDistro string
SpecCPU string
SpecGPU string
SpecRAM string
SpecKernel string
SpecScheduler string
CreatedAtHumanized string `gorm:"-"` // Human readable "X h/m/s ago" version of CreatedAt (filled automatically)
User User `gorm:"foreignKey:UserID;"`
}
// AfterFind is a GORM hook that is called after a record is found
func (b *Benchmark) AfterFind(tx *gorm.DB) (err error) {
b.CreatedAtHumanized = humanize.Time(b.CreatedAt)
return nil
}