summaryrefslogtreecommitdiffstats
path: root/models/upload.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/upload.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/upload.go')
-rw-r--r--models/upload.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/models/upload.go b/models/upload.go
index de2032fb72..ca88c6a393 100644
--- a/models/upload.go
+++ b/models/upload.go
@@ -12,6 +12,7 @@ import (
"os"
"path"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -34,6 +35,10 @@ type Upload struct {
Name string
}
+func init() {
+ db.RegisterModel(new(Upload))
+}
+
// UploadLocalPath returns where uploads is stored in local file system based on given UUID.
func UploadLocalPath(uuid string) string {
return path.Join(setting.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
@@ -68,7 +73,7 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err
return nil, fmt.Errorf("Copy: %v", err)
}
- if _, err := x.Insert(upload); err != nil {
+ if _, err := db.DefaultContext().Engine().Insert(upload); err != nil {
return nil, err
}
@@ -78,7 +83,7 @@ func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err err
// GetUploadByUUID returns the Upload by UUID
func GetUploadByUUID(uuid string) (*Upload, error) {
upload := &Upload{}
- has, err := x.Where("uuid=?", uuid).Get(upload)
+ has, err := db.DefaultContext().Engine().Where("uuid=?", uuid).Get(upload)
if err != nil {
return nil, err
} else if !has {
@@ -95,7 +100,7 @@ func GetUploadsByUUIDs(uuids []string) ([]*Upload, error) {
// Silently drop invalid uuids.
uploads := make([]*Upload, 0, len(uuids))
- return uploads, x.In("uuid", uuids).Find(&uploads)
+ return uploads, db.DefaultContext().Engine().In("uuid", uuids).Find(&uploads)
}
// DeleteUploads deletes multiple uploads
@@ -104,7 +109,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
return nil
}
- sess := x.NewSession()
+ sess := db.DefaultContext().NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err