Skip to content

Commit

Permalink
Fix guess conn pool when using dbresolver.Read clause
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Aug 14, 2023
1 parent f99ec1a commit f13c0af
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (dr *DBResolver) switchGuess(db *gorm.DB) {
if !isTransaction(db.Statement.ConnPool) {
if _, ok := db.Statement.Settings.Load(writeName); ok {
db.Statement.ConnPool = dr.resolve(db.Statement, Write)
} else if _, ok := db.Statement.Settings.Load(readName); ok {
db.Statement.ConnPool = dr.resolve(db.Statement, Read)
} else if rawSQL := strings.TrimSpace(db.Statement.SQL.String()); len(rawSQL) > 10 && strings.EqualFold(rawSQL[:6], "select") && !strings.EqualFold(rawSQL[len(rawSQL)-10:], "for update") {
db.Statement.ConnPool = dr.resolve(db.Statement, Read)
} else {
Expand Down

0 comments on commit f13c0af

Please sign in to comment.