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

Method Execute

callbacks.go:75–159  ·  view source on GitHub ↗
(db *DB)

Source from the content-addressed store, hash-verified

73}
74
75func (p *processor) Execute(db *DB) *DB {
76 // call scopes
77 for len(db.Statement.scopes) > 0 {
78 db = db.executeScopes()
79 }
80
81 var (
82 curTime = time.Now()
83 stmt = db.Statement
84 resetBuildClauses bool
85 )
86
87 if len(stmt.BuildClauses) == 0 {
88 stmt.BuildClauses = p.Clauses
89 resetBuildClauses = true
90 }
91
92 if optimizer, ok := stmt.Dest.(StatementModifier); ok {
93 optimizer.ModifyStatement(stmt)
94 }
95
96 if db.DefaultContextTimeout > 0 {
97 if _, ok := stmt.Context.Deadline(); !ok {
98 stmt.Context, _ = context.WithTimeout(stmt.Context, db.DefaultContextTimeout)
99 }
100 }
101
102 // assign model values
103 if stmt.Model == nil {
104 stmt.Model = stmt.Dest
105 } else if stmt.Dest == nil {
106 stmt.Dest = stmt.Model
107 }
108
109 // parse model values
110 if stmt.Model != nil {
111 if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.TableExpr == nil && stmt.SQL.Len() == 0)) {
112 if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" && stmt.TableExpr == nil {
113 db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err))
114 } else {
115 db.AddError(err)
116 }
117 }
118 }
119
120 // assign stmt.ReflectValue
121 if stmt.Dest != nil {
122 stmt.ReflectValue = reflect.ValueOf(stmt.Dest)
123 for stmt.ReflectValue.Kind() == reflect.Ptr {
124 if stmt.ReflectValue.IsNil() && stmt.ReflectValue.CanAddr() {
125 stmt.ReflectValue.Set(reflect.New(stmt.ReflectValue.Type().Elem()))
126 }
127
128 stmt.ReflectValue = stmt.ReflectValue.Elem()
129 }
130 if !stmt.ReflectValue.IsValid() {
131 db.AddError(ErrInvalidValue)
132 }

Callers 15

AddVarMethod · 0.80
CreateMethod · 0.80
CreateInBatchesMethod · 0.80
SaveMethod · 0.80
FirstMethod · 0.80
TakeMethod · 0.80
LastMethod · 0.80
FindMethod · 0.80
UpdateMethod · 0.80
UpdatesMethod · 0.80
UpdateColumnMethod · 0.80
UpdateColumnsMethod · 0.80

Calls 13

executeScopesMethod · 0.80
ParseMethod · 0.80
LenMethod · 0.80
ResetMethod · 0.80
ModifyStatementMethod · 0.65
AddErrorMethod · 0.65
SetMethod · 0.65
NewMethod · 0.65
TypeMethod · 0.65
TraceMethod · 0.65
ParamsFilterMethod · 0.65
ExplainMethod · 0.65

Tested by

no test coverage detected