(db *DB)
| 73 | } |
| 74 | |
| 75 | func (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 | } |
no test coverage detected