summaryrefslogtreecommitdiffstats
path: root/models/repo_archiver.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/repo_archiver.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/repo_archiver.go')
-rw-r--r--models/repo_archiver.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/models/repo_archiver.go b/models/repo_archiver.go
index 677f0d3e80..b268e65e0d 100644
--- a/models/repo_archiver.go
+++ b/models/repo_archiver.go
@@ -7,6 +7,7 @@ package models
import (
"fmt"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/timeutil"
)
@@ -31,6 +32,10 @@ type RepoArchiver struct {
CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"`
}
+func init() {
+ db.RegisterModel(new(RepoArchiver))
+}
+
// LoadRepo loads repository
func (archiver *RepoArchiver) LoadRepo() (*Repository, error) {
if archiver.Repo != nil {
@@ -38,7 +43,7 @@ func (archiver *RepoArchiver) LoadRepo() (*Repository, error) {
}
var repo Repository
- has, err := x.ID(archiver.RepoID).Get(&repo)
+ has, err := db.DefaultContext().Engine().ID(archiver.RepoID).Get(&repo)
if err != nil {
return nil, err
}
@@ -56,9 +61,9 @@ func (archiver *RepoArchiver) RelativePath() (string, error) {
}
// GetRepoArchiver get an archiver
-func GetRepoArchiver(ctx DBContext, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) {
+func GetRepoArchiver(ctx *db.Context, repoID int64, tp git.ArchiveType, commitID string) (*RepoArchiver, error) {
var archiver RepoArchiver
- has, err := ctx.e.Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver)
+ has, err := ctx.Engine().Where("repo_id=?", repoID).And("`type`=?", tp).And("commit_id=?", commitID).Get(&archiver)
if err != nil {
return nil, err
}
@@ -69,19 +74,19 @@ func GetRepoArchiver(ctx DBContext, repoID int64, tp git.ArchiveType, commitID s
}
// AddRepoArchiver adds an archiver
-func AddRepoArchiver(ctx DBContext, archiver *RepoArchiver) error {
- _, err := ctx.e.Insert(archiver)
+func AddRepoArchiver(ctx *db.Context, archiver *RepoArchiver) error {
+ _, err := ctx.Engine().Insert(archiver)
return err
}
// UpdateRepoArchiverStatus updates archiver's status
-func UpdateRepoArchiverStatus(ctx DBContext, archiver *RepoArchiver) error {
- _, err := ctx.e.ID(archiver.ID).Cols("status").Update(archiver)
+func UpdateRepoArchiverStatus(ctx *db.Context, archiver *RepoArchiver) error {
+ _, err := ctx.Engine().ID(archiver.ID).Cols("status").Update(archiver)
return err
}
// DeleteAllRepoArchives deletes all repo archives records
func DeleteAllRepoArchives() error {
- _, err := x.Where("1=1").Delete(new(RepoArchiver))
+ _, err := db.DefaultContext().Engine().Where("1=1").Delete(new(RepoArchiver))
return err
}