Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OnlyTrashed ¶
OnlyTrashed returns a GORM scope that returns only soft-deleted records.
db.Scopes(models.OnlyTrashed).Find(&users)
Types ¶
type BaseModel ¶
type BaseModel struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
BaseModel provides common fields for all models. Embed this in your model structs to get ID, CreatedAt, UpdatedAt, and soft delete support via DeletedAt.
type UUIDBaseModel ¶ added in v2.7.0
type UUIDBaseModel struct {
ID string `gorm:"type:char(36);primaryKey" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
UUIDBaseModel provides common fields for models using UUID primary keys. Embed this instead of BaseModel when your model needs string-based UUIDs. The ID is auto-generated via a BeforeCreate GORM hook if not set.
func (*UUIDBaseModel) BeforeCreate ¶ added in v2.7.0
func (m *UUIDBaseModel) BeforeCreate(tx *gorm.DB) error
BeforeCreate generates a UUID v4 if ID is empty.
Click to show internal directories.
Click to hide internal directories.