Documentation
¶
Overview ¶
Package patterns provides soft delete functionality and patterns for DynamORM model operations.
Index ¶
- func GetItemDeletionInfo(model SoftDeletable) (deletedAt *time.Time, deletedBy string, isDeleted bool)
- func IsItemDeleted(model SoftDeletable) bool
- func RestoreItem(ctx context.Context, repo *SoftDeleteRepository, model SoftDeletable) error
- func SoftDeleteByUser(ctx context.Context, repo *SoftDeleteRepository, model SoftDeletable, ...) error
- type ExampleModel
- type SoftDeletable
- type SoftDeleteModel
- func (m *SoftDeleteModel) GetDeletedAt() *time.Time
- func (m *SoftDeleteModel) GetDeletedBy() string
- func (m *SoftDeleteModel) IsDeleted() bool
- func (m *SoftDeleteModel) Restore()
- func (m *SoftDeleteModel) SetDeletedAt(deletedAt *time.Time)
- func (m *SoftDeleteModel) SetDeletedBy(deletedBy string)
- func (m *SoftDeleteModel) SoftDelete()
- func (m *SoftDeleteModel) SoftDeleteBy(userID string)
- type SoftDeleteRepository
- func (r *SoftDeleteRepository) CleanupOldDeletes(ctx context.Context, model interface{}, olderThan time.Duration, batchSize int) (int, error)
- func (r *SoftDeleteRepository) Get(ctx context.Context, model SoftDeletable, pk, sk interface{}) error
- func (r *SoftDeleteRepository) GetDeletedItemsOlderThan(ctx context.Context, model interface{}, dest interface{}, ...) error
- func (r *SoftDeleteRepository) GetSoftDeleteStats(ctx context.Context, model interface{}) (SoftDeleteStats, error)
- func (r *SoftDeleteRepository) HardDelete(ctx context.Context, model interface{}) error
- func (r *SoftDeleteRepository) OnlyDeleted() *SoftDeleteRepository
- func (r *SoftDeleteRepository) Query(ctx context.Context, model interface{}, _ interface{}) core.Query
- func (r *SoftDeleteRepository) QueryOnlyDeleted(ctx context.Context, model interface{}) core.Query
- func (r *SoftDeleteRepository) Restore(ctx context.Context, model SoftDeletable) error
- func (r *SoftDeleteRepository) Scan(ctx context.Context, model interface{}) core.Query
- func (r *SoftDeleteRepository) ScanOnlyDeleted(ctx context.Context, model interface{}) core.Query
- func (r *SoftDeleteRepository) SoftDelete(ctx context.Context, model SoftDeletable, userID string) error
- func (r *SoftDeleteRepository) WithDeleted() *SoftDeleteRepository
- type SoftDeleteStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetItemDeletionInfo ¶
func GetItemDeletionInfo(model SoftDeletable) (deletedAt *time.Time, deletedBy string, isDeleted bool)
GetItemDeletionInfo returns deletion information for an item
func IsItemDeleted ¶
func IsItemDeleted(model SoftDeletable) bool
IsItemDeleted is a convenience function to check if an item is soft-deleted
func RestoreItem ¶
func RestoreItem(ctx context.Context, repo *SoftDeleteRepository, model SoftDeletable) error
RestoreItem is a convenience function to restore a soft-deleted item
func SoftDeleteByUser ¶
func SoftDeleteByUser(ctx context.Context, repo *SoftDeleteRepository, model SoftDeletable, userID string) error
SoftDeleteByUser is a convenience function to soft delete with user tracking
Types ¶
type ExampleModel ¶
type ExampleModel struct {
PK string `theorydb:"pk" json:"pk"` // Primary key for DynamORM
SK string `theorydb:"sk" json:"sk"` // Sort key for DynamORM
ID string `json:"id"` // Business ID
Name string `json:"name"`
Email string `json:"email"`
// Embed soft delete functionality
SoftDeleteModel
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
ExampleModel demonstrates usage of soft delete pattern with DynamORM
func NewExampleModel ¶
func NewExampleModel(id, name, email string) *ExampleModel
NewExampleModel creates a new example model with proper DynamORM keys
type SoftDeletable ¶
type SoftDeletable interface {
SoftDelete()
Restore()
IsDeleted() bool
GetDeletedAt() *time.Time
SetDeletedAt(*time.Time)
GetDeletedBy() string
SetDeletedBy(string)
}
SoftDeletable interface defines methods for soft delete functionality
type SoftDeleteModel ¶
type SoftDeleteModel struct {
DeletedAt *time.Time `json:"deleted_at,omitempty"`
DeletedBy string `json:"deleted_by,omitempty"`
}
SoftDeleteModel provides default soft delete functionality
func (*SoftDeleteModel) GetDeletedAt ¶
func (m *SoftDeleteModel) GetDeletedAt() *time.Time
GetDeletedAt returns the deletion timestamp
func (*SoftDeleteModel) GetDeletedBy ¶
func (m *SoftDeleteModel) GetDeletedBy() string
GetDeletedBy returns the user who deleted this entity
func (*SoftDeleteModel) IsDeleted ¶
func (m *SoftDeleteModel) IsDeleted() bool
IsDeleted returns true if the entity is soft deleted
func (*SoftDeleteModel) Restore ¶
func (m *SoftDeleteModel) Restore()
Restore removes the soft delete marker
func (*SoftDeleteModel) SetDeletedAt ¶
func (m *SoftDeleteModel) SetDeletedAt(deletedAt *time.Time)
SetDeletedAt sets the deletion timestamp
func (*SoftDeleteModel) SetDeletedBy ¶
func (m *SoftDeleteModel) SetDeletedBy(deletedBy string)
SetDeletedBy sets the user who deleted this entity
func (*SoftDeleteModel) SoftDelete ¶
func (m *SoftDeleteModel) SoftDelete()
SoftDelete marks the entity as deleted
func (*SoftDeleteModel) SoftDeleteBy ¶
func (m *SoftDeleteModel) SoftDeleteBy(userID string)
SoftDeleteBy marks the entity as deleted by a specific user
type SoftDeleteRepository ¶
type SoftDeleteRepository struct {
// contains filtered or unexported fields
}
SoftDeleteRepository provides repository methods with soft delete support using DynamORM
func NewSoftDeleteRepository ¶
func NewSoftDeleteRepository(db core.DB, logger *zap.Logger) *SoftDeleteRepository
NewSoftDeleteRepository creates a new soft delete repository using DynamORM
func (*SoftDeleteRepository) CleanupOldDeletes ¶
func (r *SoftDeleteRepository) CleanupOldDeletes(ctx context.Context, model interface{}, olderThan time.Duration, batchSize int) (int, error)
CleanupOldDeletes permanently removes items that have been soft-deleted for longer than the specified duration
func (*SoftDeleteRepository) Get ¶
func (r *SoftDeleteRepository) Get(ctx context.Context, model SoftDeletable, pk, sk interface{}) error
Get retrieves an item by primary key, optionally including soft-deleted items
func (*SoftDeleteRepository) GetDeletedItemsOlderThan ¶
func (r *SoftDeleteRepository) GetDeletedItemsOlderThan(ctx context.Context, model interface{}, dest interface{}, olderThan time.Duration) error
GetDeletedItemsOlderThan returns items that have been soft-deleted for longer than the specified duration
func (*SoftDeleteRepository) GetSoftDeleteStats ¶
func (r *SoftDeleteRepository) GetSoftDeleteStats(ctx context.Context, model interface{}) (SoftDeleteStats, error)
GetSoftDeleteStats returns statistics about soft-deleted items
func (*SoftDeleteRepository) HardDelete ¶
func (r *SoftDeleteRepository) HardDelete(ctx context.Context, model interface{}) error
HardDelete permanently deletes an item from DynamoDB using DynamORM
func (*SoftDeleteRepository) OnlyDeleted ¶
func (r *SoftDeleteRepository) OnlyDeleted() *SoftDeleteRepository
OnlyDeleted returns a new repository instance that only returns soft-deleted items
func (*SoftDeleteRepository) Query ¶
func (r *SoftDeleteRepository) Query(ctx context.Context, model interface{}, _ interface{}) core.Query
Query performs a query with soft delete filtering using DynamORM
func (*SoftDeleteRepository) QueryOnlyDeleted ¶
func (r *SoftDeleteRepository) QueryOnlyDeleted(ctx context.Context, model interface{}) core.Query
QueryOnlyDeleted queries only soft-deleted items using DynamORM
func (*SoftDeleteRepository) Restore ¶
func (r *SoftDeleteRepository) Restore(ctx context.Context, model SoftDeletable) error
Restore restores a soft-deleted item
func (*SoftDeleteRepository) Scan ¶
func (r *SoftDeleteRepository) Scan(ctx context.Context, model interface{}) core.Query
Scan performs a scan with soft delete filtering using DynamORM
func (*SoftDeleteRepository) ScanOnlyDeleted ¶
func (r *SoftDeleteRepository) ScanOnlyDeleted(ctx context.Context, model interface{}) core.Query
ScanOnlyDeleted scans only soft-deleted items using DynamORM
func (*SoftDeleteRepository) SoftDelete ¶
func (r *SoftDeleteRepository) SoftDelete(ctx context.Context, model SoftDeletable, userID string) error
SoftDelete performs a soft delete operation
func (*SoftDeleteRepository) WithDeleted ¶
func (r *SoftDeleteRepository) WithDeleted() *SoftDeleteRepository
WithDeleted returns a new repository instance that includes soft-deleted items in queries
type SoftDeleteStats ¶
type SoftDeleteStats struct {
TotalItems int `json:"total_items"`
ActiveItems int `json:"active_items"`
DeletedItems int `json:"deleted_items"`
}
SoftDeleteStats contains statistics about soft-deleted items
func (SoftDeleteStats) GetDeletionPercentage ¶
func (s SoftDeleteStats) GetDeletionPercentage() float64
GetDeletionPercentage returns the percentage of items that are soft-deleted
func (SoftDeleteStats) String ¶
func (s SoftDeleteStats) String() string
String returns a string representation of soft delete stats