soft_delete

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 2 Imported by: 19 modules, 18 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// SoftDeleteAtColumn is the default column name used for soft deletes.
	// The default is "soft_deleted_at" — semantically explicit about what the column tracks.
	// Use DeletedAtColumnName for "deleted_at" (Laravel-style) compatibility.
	// Deprecated: Use constants.SoftDeleteAtColumn instead.
	SoftDeleteAtColumn = constants.SoftDeleteAtColumn

	// DeletedAtColumnName is the column name used by the DeletedAt embed (Laravel-compatible).
	// Deprecated: Use constants.DeletedAtColumnName instead.
	DeletedAtColumnName = constants.DeletedAtColumnName

	// DeletedAtColumn is an alias for SoftDeleteAtColumn.
	//
	// Deprecated: Use SoftDeleteAtColumn instead.
	DeletedAtColumn = SoftDeleteAtColumn
)

Re-export constants for backward compatibility

Variables

View Source
var MaxSoftDeletedAt = time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC)

MaxSoftDeletedAt is the sentinel "not deleted" value for the max-date strategy. Records are considered active when soft_deleted_at > NOW(), and deleted when soft_deleted_at <= NOW(). Using a far-future date (9999-12-31 23:59:59 UTC) instead of NULL allows:

  • NOT NULL column constraints
  • Better partial index support (range scans vs IS NULL)
  • Simpler query conditions without NULL handling

Functions

This section is empty.

Types

type DeletedAt added in v0.12.0

type DeletedAt struct {
	DeletedAt *time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
}

DeletedAt provides soft delete functionality using the "deleted_at" column name. Use this embed for Laravel-compatible schemas or any existing schema that uses "deleted_at".

Example:

type User struct {
    soft_delete.DeletedAt  // uses "deleted_at" (Laravel-compatible)
    ID   uint
    Name string
}

func (*DeletedAt) Delete deprecated added in v0.12.0

func (sd *DeletedAt) Delete()

Delete marks the model as soft-deleted by setting the deleted_at timestamp.

Deprecated: Use SoftDelete() instead.

func (*DeletedAt) GetDeletedAt deprecated added in v0.12.0

func (sd *DeletedAt) GetDeletedAt() *time.Time

GetDeletedAt returns the deleted_at timestamp.

Deprecated: Use GetSoftDeletedAt() instead.

func (*DeletedAt) GetSoftDeletedAt added in v0.12.0

func (sd *DeletedAt) GetSoftDeletedAt() *time.Time

GetSoftDeletedAt returns the deleted_at timestamp.

func (*DeletedAt) IsDeleted deprecated added in v0.12.0

func (sd *DeletedAt) IsDeleted() bool

IsDeleted returns true if the model has been soft deleted.

Deprecated: Use IsSoftDeleted() instead.

func (*DeletedAt) IsSoftDeleted added in v0.12.0

func (sd *DeletedAt) IsSoftDeleted() bool

IsSoftDeleted returns true if the model has been soft deleted.

func (*DeletedAt) Restore deprecated added in v0.12.0

func (sd *DeletedAt) Restore()

Restore marks the model as not soft-deleted by setting deleted_at to nil.

Deprecated: Use RestoreSoftDeleted() instead.

func (*DeletedAt) RestoreSoftDeleted added in v0.12.0

func (sd *DeletedAt) RestoreSoftDeleted()

RestoreSoftDeleted marks the model as not soft-deleted by setting deleted_at to nil.

func (*DeletedAt) SoftDelete added in v0.12.0

func (sd *DeletedAt) SoftDelete()

SoftDelete marks the model as soft-deleted by setting the deleted_at timestamp.

func (*DeletedAt) SoftDeletedAtColumn added in v0.12.0

func (sd *DeletedAt) SoftDeletedAtColumn() string

SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.

type DeletedAtMaxDate added in v0.12.0

type DeletedAtMaxDate struct {
	DeletedAt time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
}

DeletedAtMaxDate provides soft delete functionality using a max-date sentinel with the "deleted_at" column name (Laravel-compatible). Use this when your schema uses "deleted_at" and enforces NOT NULL.

Records are soft-deleted when deleted_at is in the past (<= NOW()), and active when deleted_at is in the future (e.g., MaxSoftDeletedAt).

Example:

type Post struct {
    soft_delete.DeletedAtMaxDate  // uses "deleted_at" with sentinel
    ID    uint
    Title string
}

func (*DeletedAtMaxDate) Delete deprecated added in v0.12.0

func (s *DeletedAtMaxDate) Delete()

Delete marks the model as soft-deleted by setting deleted_at to NOW().

Deprecated: Use SoftDelete() instead.

func (*DeletedAtMaxDate) DeletedAtColumn deprecated added in v0.12.0

func (s *DeletedAtMaxDate) DeletedAtColumn() string

DeletedAtColumn returns the soft delete column name used in database queries.

Deprecated: Use SoftDeletedAtColumn() instead.

func (*DeletedAtMaxDate) GetDeletedAt deprecated added in v0.12.0

func (s *DeletedAtMaxDate) GetDeletedAt() time.Time

GetDeletedAt returns the deleted_at timestamp.

Deprecated: Use GetSoftDeletedAt() instead.

func (*DeletedAtMaxDate) GetSoftDeletedAt added in v0.12.0

func (s *DeletedAtMaxDate) GetSoftDeletedAt() time.Time

GetSoftDeletedAt returns the deleted_at timestamp.

func (*DeletedAtMaxDate) IsDeleted deprecated added in v0.12.0

func (s *DeletedAtMaxDate) IsDeleted() bool

IsDeleted returns true if the model has been soft deleted.

Deprecated: Use IsSoftDeleted() instead.

func (*DeletedAtMaxDate) IsSoftDeleted added in v0.12.0

func (s *DeletedAtMaxDate) IsSoftDeleted() bool

IsSoftDeleted returns true if the model has been soft deleted. A record is soft-deleted when deleted_at <= NOW().

func (*DeletedAtMaxDate) NotSoftDeletedCondition added in v0.12.0

func (s *DeletedAtMaxDate) NotSoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)

NotSoftDeletedCondition returns the SQL fragment + args for the "not soft deleted" filter. Implements the SoftDeleteStrategy interface.

func (*DeletedAtMaxDate) Restore deprecated added in v0.12.0

func (s *DeletedAtMaxDate) Restore()

Restore marks the model as not soft-deleted by setting deleted_at to MaxSoftDeletedAt.

Deprecated: Use RestoreSoftDeleted() instead.

func (*DeletedAtMaxDate) RestoreSoftDeleted added in v0.12.0

func (s *DeletedAtMaxDate) RestoreSoftDeleted()

RestoreSoftDeleted marks the model as not soft-deleted by setting deleted_at to MaxSoftDeletedAt.

func (*DeletedAtMaxDate) RestoreValue added in v0.12.0

func (s *DeletedAtMaxDate) RestoreValue() any

RestoreValue returns the value to write on restore. Implements the SoftDeleteStrategy interface.

func (*DeletedAtMaxDate) SoftDelete added in v0.12.0

func (s *DeletedAtMaxDate) SoftDelete()

SoftDelete marks the model as soft-deleted by setting deleted_at to NOW().

func (*DeletedAtMaxDate) SoftDeleteValue added in v0.12.0

func (s *DeletedAtMaxDate) SoftDeleteValue() any

SoftDeleteValue returns the value to write on soft delete. Implements the SoftDeleteStrategy interface.

func (*DeletedAtMaxDate) SoftDeletedAtColumn added in v0.12.0

func (s *DeletedAtMaxDate) SoftDeletedAtColumn() string

SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.

func (*DeletedAtMaxDate) SoftDeletedCondition added in v0.12.0

func (s *DeletedAtMaxDate) SoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)

SoftDeletedCondition returns the SQL fragment + args for the "only soft deleted" filter. Implements the SoftDeleteStrategy interface.

type SoftDeletedAt added in v0.12.0

type SoftDeletedAt struct {
	SoftDeletedAt *time.Time `json:"soft_deleted_at,omitempty" db:"soft_deleted_at"`
}

SoftDeletedAt provides soft delete functionality using the "soft_deleted_at" column name. Identical to SoftDeletes — provided for explicit naming consistency with CreatedAt/UpdatedAt.

Example:

type User struct {
    soft_delete.SoftDeletedAt  // uses "soft_deleted_at"
    ID   uint
    Name string
}

func (*SoftDeletedAt) Delete deprecated added in v0.12.0

func (sd *SoftDeletedAt) Delete()

Delete marks the model as soft-deleted by setting the soft_deleted_at timestamp.

Deprecated: Use SoftDelete() instead.

func (*SoftDeletedAt) DeletedAtColumn deprecated added in v0.12.0

func (sd *SoftDeletedAt) DeletedAtColumn() string

DeletedAtColumn returns the soft delete column name used in database queries.

Deprecated: Use SoftDeletedAtColumn() instead.

func (*SoftDeletedAt) GetDeletedAt deprecated added in v0.12.0

func (sd *SoftDeletedAt) GetDeletedAt() *time.Time

GetDeletedAt returns the soft_deleted_at timestamp.

Deprecated: Use GetSoftDeletedAt() instead.

func (*SoftDeletedAt) GetSoftDeletedAt added in v0.12.0

func (sd *SoftDeletedAt) GetSoftDeletedAt() *time.Time

GetSoftDeletedAt returns the soft_deleted_at timestamp.

func (*SoftDeletedAt) IsDeleted deprecated added in v0.12.0

func (sd *SoftDeletedAt) IsDeleted() bool

IsDeleted returns true if the model has been soft deleted.

Deprecated: Use IsSoftDeleted() instead.

func (*SoftDeletedAt) IsSoftDeleted added in v0.12.0

func (sd *SoftDeletedAt) IsSoftDeleted() bool

IsSoftDeleted returns true if the model has been soft deleted.

func (*SoftDeletedAt) Restore deprecated added in v0.12.0

func (sd *SoftDeletedAt) Restore()

Restore marks the model as not soft-deleted by setting soft_deleted_at to nil.

Deprecated: Use RestoreSoftDeleted() instead.

func (*SoftDeletedAt) RestoreSoftDeleted added in v0.12.0

func (sd *SoftDeletedAt) RestoreSoftDeleted()

RestoreSoftDeleted marks the model as not soft-deleted by setting soft_deleted_at to nil.

func (*SoftDeletedAt) SoftDelete added in v0.12.0

func (sd *SoftDeletedAt) SoftDelete()

SoftDelete marks the model as soft-deleted by setting the soft_deleted_at timestamp.

func (*SoftDeletedAt) SoftDeletedAtColumn added in v0.12.0

func (sd *SoftDeletedAt) SoftDeletedAtColumn() string

SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.

type SoftDeletes

type SoftDeletes struct {
	SoftDeletedAt *time.Time `json:"soft_deleted_at,omitempty" db:"soft_deleted_at"`
}

SoftDeletes provides soft delete functionality for models using the "soft_deleted_at" column. This is the default embed for new projects — the column name is semantically explicit.

To use the Laravel-compatible "deleted_at" column, embed DeletedAt instead.

Example:

type User struct {
    soft_delete.SoftDeletes  // uses "soft_deleted_at"
    ID   uint
    Name string
}

func (*SoftDeletes) Delete deprecated

func (sd *SoftDeletes) Delete()

Delete marks the model as soft-deleted by setting the soft_deleted_at timestamp.

Deprecated: Use SoftDelete() instead.

func (*SoftDeletes) DeletedAtColumn deprecated added in v0.12.0

func (sd *SoftDeletes) DeletedAtColumn() string

DeletedAtColumn returns the soft delete column name used in database queries.

Deprecated: Use SoftDeletedAtColumn() instead.

func (*SoftDeletes) GetDeletedAt deprecated

func (sd *SoftDeletes) GetDeletedAt() *time.Time

GetDeletedAt returns the soft_deleted_at timestamp.

Deprecated: Use GetSoftDeletedAt() instead.

func (*SoftDeletes) GetSoftDeletedAt added in v0.12.0

func (sd *SoftDeletes) GetSoftDeletedAt() *time.Time

GetSoftDeletedAt returns the soft_deleted_at timestamp.

func (*SoftDeletes) IsDeleted deprecated

func (sd *SoftDeletes) IsDeleted() bool

IsDeleted returns true if the model has been soft deleted.

Deprecated: Use IsSoftDeleted() instead.

func (*SoftDeletes) IsSoftDeleted added in v0.12.0

func (sd *SoftDeletes) IsSoftDeleted() bool

IsSoftDeleted returns true if the model has been soft deleted.

func (*SoftDeletes) Restore deprecated

func (sd *SoftDeletes) Restore()

Restore marks the model as not soft-deleted by setting soft_deleted_at to nil.

Deprecated: Use RestoreSoftDeleted() instead.

func (*SoftDeletes) RestoreSoftDeleted added in v0.12.0

func (sd *SoftDeletes) RestoreSoftDeleted()

RestoreSoftDeleted marks the model as not soft-deleted by setting soft_deleted_at to nil.

func (*SoftDeletes) SoftDelete added in v0.12.0

func (sd *SoftDeletes) SoftDelete()

SoftDelete marks the model as soft-deleted by setting the soft_deleted_at timestamp.

func (*SoftDeletes) SoftDeletedAtColumn added in v0.12.0

func (sd *SoftDeletes) SoftDeletedAtColumn() string

SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.

type SoftDeletesMaxDate added in v0.12.0

type SoftDeletesMaxDate struct {
	SoftDeletedAt time.Time `json:"soft_deleted_at,omitempty" db:"soft_deleted_at"`
}

SoftDeletesMaxDate provides soft delete functionality using a max-date sentinel instead of NULL. The column used is "soft_deleted_at". Embed this in models where the schema enforces NOT NULL on timestamp columns.

Records are soft-deleted when soft_deleted_at is in the past (<= NOW()), and active when soft_deleted_at is in the future (e.g., MaxSoftDeletedAt).

Example:

type User struct {
    soft_delete.SoftDeletesMaxDate  // uses "soft_deleted_at" with sentinel
    ID   uint
    Name string
}

func (*SoftDeletesMaxDate) Delete deprecated added in v0.12.0

func (s *SoftDeletesMaxDate) Delete()

Delete marks the model as soft-deleted by setting soft_deleted_at to NOW().

Deprecated: Use SoftDelete() instead.

func (*SoftDeletesMaxDate) DeletedAtColumn deprecated added in v0.12.0

func (s *SoftDeletesMaxDate) DeletedAtColumn() string

DeletedAtColumn returns the soft delete column name used in database queries.

Deprecated: Use SoftDeletedAtColumn() instead.

func (*SoftDeletesMaxDate) GetDeletedAt deprecated added in v0.12.0

func (s *SoftDeletesMaxDate) GetDeletedAt() time.Time

GetDeletedAt returns the soft_deleted_at timestamp.

Deprecated: Use GetSoftDeletedAt() instead.

func (*SoftDeletesMaxDate) GetSoftDeletedAt added in v0.12.0

func (s *SoftDeletesMaxDate) GetSoftDeletedAt() time.Time

GetSoftDeletedAt returns the soft_deleted_at timestamp.

func (*SoftDeletesMaxDate) IsDeleted deprecated added in v0.12.0

func (s *SoftDeletesMaxDate) IsDeleted() bool

IsDeleted returns true if the model has been soft deleted.

Deprecated: Use IsSoftDeleted() instead.

func (*SoftDeletesMaxDate) IsSoftDeleted added in v0.12.0

func (s *SoftDeletesMaxDate) IsSoftDeleted() bool

IsSoftDeleted returns true if the model has been soft deleted. A record is soft-deleted when soft_deleted_at <= NOW().

func (*SoftDeletesMaxDate) NotSoftDeletedCondition added in v0.12.0

func (s *SoftDeletesMaxDate) NotSoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)

NotSoftDeletedCondition returns the SQL fragment + args for the "not soft deleted" filter. Implements the SoftDeleteStrategy interface.

func (*SoftDeletesMaxDate) Restore deprecated added in v0.12.0

func (s *SoftDeletesMaxDate) Restore()

Restore marks the model as not soft-deleted by setting soft_deleted_at to MaxSoftDeletedAt.

Deprecated: Use RestoreSoftDeleted() instead.

func (*SoftDeletesMaxDate) RestoreSoftDeleted added in v0.12.0

func (s *SoftDeletesMaxDate) RestoreSoftDeleted()

RestoreSoftDeleted marks the model as not soft-deleted by setting soft_deleted_at to MaxSoftDeletedAt.

func (*SoftDeletesMaxDate) RestoreValue added in v0.12.0

func (s *SoftDeletesMaxDate) RestoreValue() any

RestoreValue returns the value to write on restore. Implements the SoftDeleteStrategy interface.

func (*SoftDeletesMaxDate) SoftDelete added in v0.12.0

func (s *SoftDeletesMaxDate) SoftDelete()

SoftDelete marks the model as soft-deleted by setting soft_deleted_at to NOW().

func (*SoftDeletesMaxDate) SoftDeleteValue added in v0.12.0

func (s *SoftDeletesMaxDate) SoftDeleteValue() any

SoftDeleteValue returns the value to write on soft delete. Implements the SoftDeleteStrategy interface.

func (*SoftDeletesMaxDate) SoftDeletedAtColumn added in v0.12.0

func (s *SoftDeletesMaxDate) SoftDeletedAtColumn() string

SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.

func (*SoftDeletesMaxDate) SoftDeletedCondition added in v0.12.0

func (s *SoftDeletesMaxDate) SoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)

SoftDeletedCondition returns the SQL fragment + args for the "only soft deleted" filter. Implements the SoftDeleteStrategy interface.

Jump to

Keyboard shortcuts

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