Skip to content

Commit

Permalink
fix: clone and write db (go-gorm#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
qqxhb authored Jan 19, 2023
1 parent adde295 commit a983af4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion do.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (d *DO) ReplaceDB(db *gorm.DB) {

// ReplaceConnPool replace db connection pool
func (d *DO) ReplaceConnPool(pool gorm.ConnPool) {
d.db = d.db.Session(&gorm.Session{})
d.db = d.db.Session(&gorm.Session{Initialized: true}).Session(&gorm.Session{})
d.db.Statement.ConnPool = pool
}

Expand Down
4 changes: 2 additions & 2 deletions internal/template/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (q *Query) clone(db *gorm.DB) *Query {
}
func (q *Query) ReadDB() *Query {
return q.clone(q.db.Clauses(dbresolver.Read))
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.clone(q.db.Clauses(dbresolver.Write))
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
Expand Down
4 changes: 2 additions & 2 deletions tests/.expect/dal_1/query/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.expect/dal_2/query/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.expect/dal_3/query/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.expect/dal_test/query/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a983af4

Please sign in to comment.