Files
pocket-id-pocket-id/backend/internal/model/base.go

24 lines
474 B
Go
Raw Normal View History

2024-08-12 11:00:25 +02:00
package model
import (
"time"
2024-08-12 11:00:25 +02:00
"github.com/google/uuid"
"github.com/pocket-id/pocket-id/backend/internal/model/types"
2024-08-12 11:00:25 +02:00
"gorm.io/gorm"
)
// Base contains common columns for all tables.
type Base struct {
ID string `gorm:"primaryKey;not null"`
CreatedAt datatype.DateTime `sortable:"true"`
2024-08-12 11:00:25 +02:00
}
func (b *Base) BeforeCreate(_ *gorm.DB) (err error) {
2024-08-12 11:00:25 +02:00
if b.ID == "" {
b.ID = uuid.New().String()
}
b.CreatedAt = datatype.DateTime(time.Now())
2024-08-12 11:00:25 +02:00
return
}