models

package
v2.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnlyTrashed

func OnlyTrashed(db *gorm.DB) *gorm.DB

OnlyTrashed returns a GORM scope that returns only soft-deleted records.

db.Scopes(models.OnlyTrashed).Find(&users)

func WithTrashed

func WithTrashed(db *gorm.DB) *gorm.DB

WithTrashed returns a GORM scope that includes soft-deleted records.

db.Scopes(models.WithTrashed).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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL