feat: support softdelete in table functions

This commit is contained in:
yanghao05
2025-05-23 22:24:53 +08:00
parent ab36ea0e5d
commit e83332ea6a
2 changed files with 16 additions and 0 deletions

View File

@@ -44,6 +44,8 @@ func (m *{{.PascalTable}}) BatchCreate(ctx context.Context, models []*{{.PascalT
return nil
}
// if SoftDelete
{{- if .SoftDelete }}
func (m *{{.PascalTable}}) Delete(ctx context.Context) error {
stmt := table.{{.PascalTable}}.UPDATE().SET(table.{{.PascalTable}}.DeletedAt.Set(TimestampzT(time.Now()))).WHERE(table.{{.PascalTable}}.ID.EQ(Int(m.ID)))
@@ -75,6 +77,7 @@ func (m *{{.PascalTable}}) BatchDelete(ctx context.Context, ids []int64) error {
m.log().WithField("func", "BatchSoftDelete").Infof("{{.PascalTable}} items soft deleted successfully")
return nil
}
{{- end}}
func (m *{{.PascalTable}}) ForceDelete(ctx context.Context) error {