MCPcopy
hub / github.com/go-gorm/gorm / callMethod

Function callMethod

callbacks/callmethod.go:9–32  ·  view source on GitHub ↗
(db *gorm.DB, fc func(value interface{}, tx *gorm.DB) bool)

Source from the content-addressed store, hash-verified

7)
8
9func callMethod(db *gorm.DB, fc func(value interface{}, tx *gorm.DB) bool) {
10 tx := db.Session(&gorm.Session{NewDB: true})
11 if called := fc(db.Statement.ReflectValue.Interface(), tx); !called {
12 switch db.Statement.ReflectValue.Kind() {
13 case reflect.Slice, reflect.Array:
14 db.Statement.CurDestIndex = 0
15 for i := 0; i < db.Statement.ReflectValue.Len(); i++ {
16 if value := reflect.Indirect(db.Statement.ReflectValue.Index(i)); value.CanAddr() {
17 fc(value.Addr().Interface(), tx)
18 } else {
19 db.AddError(gorm.ErrInvalidValue)
20 return
21 }
22 db.Statement.CurDestIndex++
23 }
24 case reflect.Struct:
25 if db.Statement.ReflectValue.CanAddr() {
26 fc(db.Statement.ReflectValue.Addr().Interface(), tx)
27 } else {
28 db.AddError(gorm.ErrInvalidValue)
29 }
30 }
31 }
32}

Callers 8

AfterQueryFunction · 0.85
BeforeUpdateFunction · 0.85
AfterUpdateFunction · 0.85
BeforeDeleteFunction · 0.85
AfterDeleteFunction · 0.85
BeforeCreateFunction · 0.85
AfterCreateFunction · 0.85
TestCallbacksFunction · 0.85

Calls 3

SessionMethod · 0.80
LenMethod · 0.80
AddErrorMethod · 0.65

Tested by 1

TestCallbacksFunction · 0.68