aboutsummaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-04-05 00:56:31 +0800
committerGitHub <noreply@github.com>2020-04-05 00:56:31 +0800
commit3a5c93eeff470dda5dc4f729a1d3eef3bcb8622b (patch)
treeb647fc449341a5fb1006a2c70d479ebe4377b15b /internal/db
parent4aff4d66ec3e118248129505bc1d70395f47dfbb (diff)
db: use gorm function to check `ErrRecordNotFound` (#6060)
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/access_tokens.go2
-rw-r--r--internal/db/lfs.go2
-rw-r--r--internal/db/login_sources.go2
-rw-r--r--internal/db/repos.go2
-rw-r--r--internal/db/users.go4
5 files changed, 6 insertions, 6 deletions
diff --git a/internal/db/access_tokens.go b/internal/db/access_tokens.go
index ad5e6c7a..c3be93ac 100644
--- a/internal/db/access_tokens.go
+++ b/internal/db/access_tokens.go
@@ -52,7 +52,7 @@ func (db *accessTokens) GetBySHA(sha string) (*AccessToken, error) {
token := new(AccessToken)
err := db.Where("sha1 = ?", sha).First(token).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return nil, ErrAccessTokenNotExist{args: errutil.Args{"sha": sha}}
}
return nil, err
diff --git a/internal/db/lfs.go b/internal/db/lfs.go
index bf1af0bb..3868a20c 100644
--- a/internal/db/lfs.go
+++ b/internal/db/lfs.go
@@ -107,7 +107,7 @@ func (db *lfs) GetObjectByOID(repoID int64, oid lfsutil.OID) (*LFSObject, error)
object := new(LFSObject)
err := db.Where("repo_id = ? AND oid = ?", repoID, oid).First(object).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return nil, ErrLFSObjectNotExist{args: errutil.Args{"repoID": repoID, "oid": oid}}
}
return nil, err
diff --git a/internal/db/login_sources.go b/internal/db/login_sources.go
index 91432ff4..41ee73b9 100644
--- a/internal/db/login_sources.go
+++ b/internal/db/login_sources.go
@@ -27,7 +27,7 @@ func (db *loginSources) GetByID(id int64) (*LoginSource, error) {
source := new(LoginSource)
err := db.Where("id = ?", id).First(source).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return localLoginSources.GetLoginSourceByID(id)
}
return nil, err
diff --git a/internal/db/repos.go b/internal/db/repos.go
index bcab7dbd..cac50b76 100644
--- a/internal/db/repos.go
+++ b/internal/db/repos.go
@@ -29,7 +29,7 @@ func (db *repos) GetByName(ownerID int64, name string) (*Repository, error) {
repo := new(Repository)
err := db.Where("owner_id = ? AND lower_name = ?", ownerID, strings.ToLower(name)).First(repo).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return nil, ErrRepoNotExist{args: map[string]interface{}{"ownerID": ownerID, "name": name}}
}
return nil, err
diff --git a/internal/db/users.go b/internal/db/users.go
index cadd106c..006e2089 100644
--- a/internal/db/users.go
+++ b/internal/db/users.go
@@ -117,7 +117,7 @@ func (db *users) GetByID(id int64) (*User, error) {
user := new(User)
err := db.Where("id = ?", id).First(user).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return nil, ErrUserNotExist{args: map[string]interface{}{"userID": id}}
}
return nil, err
@@ -129,7 +129,7 @@ func (db *users) GetByUsername(username string) (*User, error) {
user := new(User)
err := db.Where("lower_name = ?", strings.ToLower(username)).First(user).Error
if err != nil {
- if err == gorm.ErrRecordNotFound {
+ if gorm.IsRecordNotFoundError(err) {
return nil, ErrUserNotExist{args: map[string]interface{}{"name": username}}
}
return nil, err