record not found back to the previous mode

This commit is contained in:
daheige 2021-04-10 22:28:02 +08:00
parent d278ca49ef
commit d4a1313643
2 changed files with 3 additions and 6 deletions

View File

@ -2,13 +2,11 @@ package gorm
import (
"errors"
"gorm.io/gorm/logger"
)
var (
// ErrRecordNotFound record not found error
ErrRecordNotFound = logger.ErrRecordNotFound
ErrRecordNotFound = errors.New("record not found")
// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
ErrInvalidTransaction = errors.New("no valid transaction")
// ErrNotImplemented not implemented

View File

@ -9,11 +9,10 @@ import (
"os"
"time"
"gorm.io/gorm"
"gorm.io/gorm/utils"
)
var ErrRecordNotFound = errors.New("record not found")
// Colors
const (
Reset = "\033[0m"
@ -142,7 +141,7 @@ func (l logger) Trace(ctx context.Context, begin time.Time, fc func() (string, i
if l.LogLevel > Silent {
elapsed := time.Since(begin)
switch {
case err != nil && l.LogLevel >= Error && (!errors.Is(err, ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
case err != nil && l.LogLevel >= Error && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError):
sql, rows := fc()
if rows == -1 {
l.Printf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)