29 lines
934 B
Go
29 lines
934 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Base contains common fields for all models.
|
|
type Base struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
}
|
|
|
|
// BaseModelWithoutID is for models that define their own ID field.
|
|
// Provides timestamps and soft-delete without the ID field.
|
|
type BaseModelWithoutID struct {
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
|
|
}
|
|
|
|
// SoftDeletable marks a model as soft-deleteable via DeletedAt.
|
|
type SoftDeletable interface {
|
|
GetDeletedAt() gorm.DeletedAt
|
|
SetDeletedAt(deletedAt gorm.DeletedAt)
|
|
} |