Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor if logic #4683

Merged
merged 2 commits into from Nov 4, 2021
Merged

Refactor if logic #4683

merged 2 commits into from Nov 4, 2021

Conversation

daheige
Copy link
Contributor

@daheige daheige commented Sep 7, 2021

I think the readability of the code is more important. The unnecessary if...else can be completely removed. At the same time, the processing of err should be processed as early as possible, so that the logic can be read coherently, clearly and clearly, and it can also enhance the maintainability of the code. And expandability.

if reflect.Indirect(rv).Kind() != reflect.Struct {
break
}
insertID, err := result.LastInsertId()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some driver doesn't support LastInsertId, maybe should not return an error here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinzhu I have adjusted it, please CR/MR again

@daheige
Copy link
Contributor Author

daheige commented Sep 9, 2021 via email

@daheige daheige force-pushed the refactor-if-logic branch 2 times, most recently from 28cb41e to 1dda68d Compare September 9, 2021 13:11
if db.Statement.Schema != nil && !db.Statement.Unscoped {
for _, c := range db.Statement.Schema.UpdateClauses {
db.Statement.AddClause(c)
if db.Error == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this line uses a different code style?

@daheige
Copy link
Contributor Author

daheige commented Oct 9, 2021 via email

return
}

db.RowsAffected, err = result.RowsAffected()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error of RowsAffected doesn't matter, should not rollback the whole transaction if happens

db.AddError(err)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is not necessary?

@daheige
Copy link
Contributor Author

daheige commented Oct 15, 2021 via email

@daheige
Copy link
Contributor Author

daheige commented Oct 15, 2021 via email

@daheige
Copy link
Contributor Author

daheige commented Nov 3, 2021

@jinzhu i has adjusted these code,please CR/MR,thanks!

@jinzhu jinzhu merged commit 4c8810a into go-gorm:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants