Documentation
¶
Index ¶
- Constants
- Variables
- type DeletedAt
- func (sd *DeletedAt) Delete()deprecated
- func (sd *DeletedAt) GetDeletedAt() *time.Timedeprecated
- func (sd *DeletedAt) GetSoftDeletedAt() *time.Time
- func (sd *DeletedAt) IsDeleted() booldeprecated
- func (sd *DeletedAt) IsSoftDeleted() bool
- func (sd *DeletedAt) Restore()deprecated
- func (sd *DeletedAt) RestoreSoftDeleted()
- func (sd *DeletedAt) SoftDelete()
- func (sd *DeletedAt) SoftDeletedAtColumn() string
- type DeletedAtMaxDate
- func (s *DeletedAtMaxDate) Delete()deprecated
- func (s *DeletedAtMaxDate) DeletedAtColumn() stringdeprecated
- func (s *DeletedAtMaxDate) GetDeletedAt() time.Timedeprecated
- func (s *DeletedAtMaxDate) GetSoftDeletedAt() time.Time
- func (s *DeletedAtMaxDate) IsDeleted() booldeprecated
- func (s *DeletedAtMaxDate) IsSoftDeleted() bool
- func (s *DeletedAtMaxDate) NotSoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)
- func (s *DeletedAtMaxDate) Restore()deprecated
- func (s *DeletedAtMaxDate) RestoreSoftDeleted()
- func (s *DeletedAtMaxDate) RestoreValue() any
- func (s *DeletedAtMaxDate) SoftDelete()
- func (s *DeletedAtMaxDate) SoftDeleteValue() any
- func (s *DeletedAtMaxDate) SoftDeletedAtColumn() string
- func (s *DeletedAtMaxDate) SoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)
- type SoftDeletedAt
- func (sd *SoftDeletedAt) Delete()deprecated
- func (sd *SoftDeletedAt) DeletedAtColumn() stringdeprecated
- func (sd *SoftDeletedAt) GetDeletedAt() *time.Timedeprecated
- func (sd *SoftDeletedAt) GetSoftDeletedAt() *time.Time
- func (sd *SoftDeletedAt) IsDeleted() booldeprecated
- func (sd *SoftDeletedAt) IsSoftDeleted() bool
- func (sd *SoftDeletedAt) Restore()deprecated
- func (sd *SoftDeletedAt) RestoreSoftDeleted()
- func (sd *SoftDeletedAt) SoftDelete()
- func (sd *SoftDeletedAt) SoftDeletedAtColumn() string
- type SoftDeletes
- func (sd *SoftDeletes) Delete()deprecated
- func (sd *SoftDeletes) DeletedAtColumn() stringdeprecated
- func (sd *SoftDeletes) GetDeletedAt() *time.Timedeprecated
- func (sd *SoftDeletes) GetSoftDeletedAt() *time.Time
- func (sd *SoftDeletes) IsDeleted() booldeprecated
- func (sd *SoftDeletes) IsSoftDeleted() bool
- func (sd *SoftDeletes) Restore()deprecated
- func (sd *SoftDeletes) RestoreSoftDeleted()
- func (sd *SoftDeletes) SoftDelete()
- func (sd *SoftDeletes) SoftDeletedAtColumn() string
- type SoftDeletesMaxDate
- func (s *SoftDeletesMaxDate) Delete()deprecated
- func (s *SoftDeletesMaxDate) DeletedAtColumn() stringdeprecated
- func (s *SoftDeletesMaxDate) GetDeletedAt() time.Timedeprecated
- func (s *SoftDeletesMaxDate) GetSoftDeletedAt() time.Time
- func (s *SoftDeletesMaxDate) IsDeleted() booldeprecated
- func (s *SoftDeletesMaxDate) IsSoftDeleted() bool
- func (s *SoftDeletesMaxDate) NotSoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)
- func (s *SoftDeletesMaxDate) Restore()deprecated
- func (s *SoftDeletesMaxDate) RestoreSoftDeleted()
- func (s *SoftDeletesMaxDate) RestoreValue() any
- func (s *SoftDeletesMaxDate) SoftDelete()
- func (s *SoftDeletesMaxDate) SoftDeleteValue() any
- func (s *SoftDeletesMaxDate) SoftDeletedAtColumn() string
- func (s *SoftDeletesMaxDate) SoftDeletedCondition(quoteIdentifier func(string) string) (string, []any)
Constants ¶
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 DeletedAt embed for "deleted_at" (Laravel-style) compatibility. SoftDeleteAtColumn = "soft_deleted_at" // DeletedAtColumnName is the column name used by the DeletedAt embed (Laravel-compatible). DeletedAtColumnName = "deleted_at" // DeletedAtColumn is an alias for SoftDeleteAtColumn. // // Deprecated: Use SoftDeleteAtColumn instead. DeletedAtColumn = SoftDeleteAtColumn )
Variables ¶
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
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) GetDeletedAt
deprecated
added in
v0.12.0
func (*DeletedAt) GetSoftDeletedAt ¶ added in v0.12.0
GetSoftDeletedAt returns the deleted_at timestamp.
func (*DeletedAt) IsSoftDeleted ¶ added in v0.12.0
IsSoftDeleted returns true if the model has been soft deleted.
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
SoftDeletedAtColumn returns the soft delete column name used in database queries. Implements the SoftDeleteColumnNamer interface.
type DeletedAtMaxDate ¶ added in v0.12.0
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.