Skip to content

Commit f4c2ba9

Browse files
committed
refactor(database): 优化数据库模型中的变量声明和错误处理
1 parent 55092d5 commit f4c2ba9

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

database/gdb/gdb_model_select.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ func (m *Model) ScanAndCount(pointer any, totalCount *int, useFieldForCount bool
372372
// ScanList converts `r` to struct slice which contains other complex struct attributes.
373373
// Also see Result.ScanList.
374374
func (m *Model) ScanList(structSlicePointer any, bindToAttrName string, relationAttrNameAndFields ...string) (err error) {
375-
var (
376-
result Result
377-
)
375+
var result Result
378376
out, err := checkGetSliceElementInfoForScanList(structSlicePointer, bindToAttrName)
379377
if err != nil {
380378
return err

database/gdb/gdb_model_with.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package gdb
88

99
import (
1010
"database/sql"
11+
"errors"
1112
"reflect"
1213

1314
"github.com/gogf/gf/v2/errors/gcode"
@@ -186,7 +187,7 @@ func (m *Model) doWithScanStruct(pointer any) error {
186187
Where(relatedSourceName, relatedTargetValue).
187188
Scan(bindToReflectValue)
188189
// It ignores sql.ErrNoRows in with feature.
189-
if err != nil && err != sql.ErrNoRows {
190+
if err != nil && !errors.Is(err, sql.ErrNoRows) {
190191
return err
191192
}
192193
}
@@ -208,7 +209,7 @@ func (m *Model) doWithScanStructs(pointer any) error {
208209
reflectValue = reflect.ValueOf(pointer)
209210
reflectKind = reflectValue.Kind()
210211
)
211-
if reflectKind == reflect.Pointer {
212+
if reflectKind == reflect.Ptr {
212213
reflectValue = reflectValue.Elem()
213214
reflectKind = reflectValue.Kind()
214215
}
@@ -344,7 +345,7 @@ func (m *Model) doWithScanStructs(pointer any) error {
344345
results, err = model.Clone().Fields(field.Value).
345346
Where(relatedSourceName, relatedTargetValue).
346347
All()
347-
if err != nil && err != sql.ErrNoRows {
348+
if err != nil && !errors.Is(err, sql.ErrNoRows) {
348349
return err
349350
}
350351
}

0 commit comments

Comments
 (0)