style: prepose error judgement
This commit is contained in:
		
							parent
							
								
									a89d4d8fd5
								
							
						
					
					
						commit
						1d9e563023
					
				| @ -51,37 +51,39 @@ func BeforeUpdate(db *gorm.DB) { | ||||
| } | ||||
| 
 | ||||
| func Update(db *gorm.DB) { | ||||
| 	if db.Error == nil { | ||||
| 		if db.Statement.Schema != nil && !db.Statement.Unscoped { | ||||
| 			for _, c := range db.Statement.Schema.UpdateClauses { | ||||
| 				db.Statement.AddClause(c) | ||||
| 			} | ||||
| 		} | ||||
| 	if db.Error != nil { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 		if db.Statement.SQL.String() == "" { | ||||
| 			db.Statement.SQL.Grow(180) | ||||
| 			db.Statement.AddClauseIfNotExists(clause.Update{}) | ||||
| 			if set := ConvertToAssignments(db.Statement); len(set) != 0 { | ||||
| 				db.Statement.AddClause(set) | ||||
| 			} else { | ||||
| 				return | ||||
| 			} | ||||
| 			db.Statement.Build(db.Statement.BuildClauses...) | ||||
| 	if db.Statement.Schema != nil && !db.Statement.Unscoped { | ||||
| 		for _, c := range db.Statement.Schema.UpdateClauses { | ||||
| 			db.Statement.AddClause(c) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 		if _, ok := db.Statement.Clauses["WHERE"]; !db.AllowGlobalUpdate && !ok { | ||||
| 			db.AddError(gorm.ErrMissingWhereClause) | ||||
| 	if db.Statement.SQL.String() == "" { | ||||
| 		db.Statement.SQL.Grow(180) | ||||
| 		db.Statement.AddClauseIfNotExists(clause.Update{}) | ||||
| 		if set := ConvertToAssignments(db.Statement); len(set) != 0 { | ||||
| 			db.Statement.AddClause(set) | ||||
| 		} else { | ||||
| 			return | ||||
| 		} | ||||
| 		db.Statement.Build(db.Statement.BuildClauses...) | ||||
| 	} | ||||
| 
 | ||||
| 		if !db.DryRun && db.Error == nil { | ||||
| 			result, err := db.Statement.ConnPool.ExecContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...) | ||||
| 	if _, ok := db.Statement.Clauses["WHERE"]; !db.AllowGlobalUpdate && !ok { | ||||
| 		db.AddError(gorm.ErrMissingWhereClause) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 			if err == nil { | ||||
| 				db.RowsAffected, _ = result.RowsAffected() | ||||
| 			} else { | ||||
| 				db.AddError(err) | ||||
| 			} | ||||
| 	if !db.DryRun && db.Error == nil { | ||||
| 		result, err := db.Statement.ConnPool.ExecContext(db.Statement.Context, db.Statement.SQL.String(), db.Statement.Vars...) | ||||
| 
 | ||||
| 		if err == nil { | ||||
| 			db.RowsAffected, _ = result.RowsAffected() | ||||
| 		} else { | ||||
| 			db.AddError(err) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 riverchu
						riverchu