diff options
author | delvh <dev.lh@web.de> | 2023-12-25 21:25:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-25 21:25:29 +0100 |
commit | 778ad795fd4a19dc15723b59a846a250034c7c3a (patch) | |
tree | 8d64a21734517a9826655955d77cb0bcc187f784 /models/actions | |
parent | b41925cee3d67a1fe546c7a219174e4a8b2302b7 (diff) | |
download | gitea-778ad795fd4a19dc15723b59a846a250034c7c3a.tar.gz gitea-778ad795fd4a19dc15723b59a846a250034c7c3a.zip |
Refactor deletion (#28610)
Introduce the new generic deletion methods
- `func DeleteByID[T any](ctx context.Context, id int64) (int64, error)`
- `func DeleteByIDs[T any](ctx context.Context, ids ...int64) error`
- `func Delete[T any](ctx context.Context, opts FindOptions) (int64,
error)`
So, we no longer need any specific deletion method and can just use
the generic ones instead.
Replacement of #28450
Closes #28450
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/actions')
-rw-r--r-- | models/actions/artifact.go | 13 | ||||
-rw-r--r-- | models/actions/runner.go | 2 |
2 files changed, 1 insertions, 14 deletions
diff --git a/models/actions/artifact.go b/models/actions/artifact.go index 42bd9c23cb..5390f6288f 100644 --- a/models/actions/artifact.go +++ b/models/actions/artifact.go @@ -90,19 +90,6 @@ func getArtifactByNameAndPath(ctx context.Context, runID int64, name, fpath stri return &art, nil } -// GetArtifactByID returns an artifact by id -func GetArtifactByID(ctx context.Context, id int64) (*ActionArtifact, error) { - var art ActionArtifact - has, err := db.GetEngine(ctx).ID(id).Get(&art) - if err != nil { - return nil, err - } else if !has { - return nil, util.ErrNotExist - } - - return &art, nil -} - // UpdateArtifactByID updates an artifact by id func UpdateArtifactByID(ctx context.Context, id int64, art *ActionArtifact) error { art.ID = id diff --git a/models/actions/runner.go b/models/actions/runner.go index 5630741550..4103ba4477 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -254,7 +254,7 @@ func DeleteRunner(ctx context.Context, id int64) error { return err } - _, err := db.GetEngine(ctx).Delete(&ActionRunner{ID: id}) + _, err := db.DeleteByID[ActionRunner](ctx, id) return err } |