Files
2025-11-03 12:24:01 +02:00

22 lines
433 B
Go

package models
import (
"time"
"gorm.io/gorm"
)
type BaseModel struct {
ID ULID `gorm:"primaryKey" json:"id" db:"id" `
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}
// BeforeCreate is a GORM hook that runs before creating a record
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
if b.ID.IsZero() {
b.ID = GenerateULID()
}
return nil
}