From d208ad633efca06abd394fb1cf67432c87d099a3 Mon Sep 17 00:00:00 2001 From: gr-dv Date: Thu, 12 Oct 2023 08:21:55 +0300 Subject: [PATCH] MSP-2243 add delete method to audit repository --- repository/audit.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/repository/audit.go b/repository/audit.go index e53311b..0f8cce9 100644 --- a/repository/audit.go +++ b/repository/audit.go @@ -2,6 +2,7 @@ package repository import ( "context" + "time" "github.com/integration-system/isp-kit/db" "github.com/integration-system/isp-kit/db/query" @@ -75,3 +76,20 @@ func (r Audit) Count(ctx context.Context) (int64, error) { } return count, nil } + +func (r Audit) DeleteUpToCreatedAt(ctx context.Context, createdAt time.Time) error { + q, args, err := query.New(). + Delete("audit"). + Where("created_at < ?", createdAt). + ToSql() + if err != nil { + return errors.WithMessage(err, "build query") + } + + _, err = r.db.Exec(ctx, q, args...) + if err != nil { + return errors.WithMessagef(err, "delete audit") + } + + return nil +}