MSP-2243 add delete method to audit repository
This commit is contained in:
1 parent
a664d5db4a
commit
d208ad633e
1 file changed
+18
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user