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

feat: resolve *sql.DB based on the database context #105

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

lzakharov
Copy link
Contributor

@lzakharov lzakharov commented Jun 5, 2023

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

This PR adds ability to resolve *sql.DB connection based on the database context. It requires go-gorm/gorm#6366 (already in master).

User Case Description

At this moment all these statements return the same connection pool, ignoring provided clauses:

db.DB()
db.Clauses(dbresolver.Write).DB()
db.Clauses(dbresolver.Read).DB()
db.Clauses(dbresolver.Use("slow")).DB()
// etc

However, it should return different connections based on the current database state. See more cases inside TestConnPool.

Sorry, something went wrong.

lzakharov added 2 commits June 5, 2023 16:27

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@lzakharov lzakharov marked this pull request as ready for review July 4, 2023 08:19
@lzakharov
Copy link
Contributor Author

@jinzhu @a631807682 can you review please?

Copy link
Member

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

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

Can the functions in pool.go be made private? We don't seem to need to export for users to use.

@lzakharov
Copy link
Contributor Author

Is it possible to merge this PR now? And it would be great to make a release after that.

@lzakharov
Copy link
Contributor Author

@jinzhu @a631807682 sorry for disturbing again, any updates here?

@a631807682 a631807682 requested a review from jinzhu July 24, 2023 08:02
@jinzhu jinzhu merged commit 3522352 into go-gorm:master Jul 25, 2023
@lzakharov lzakharov deleted the add-sql-db-resolver branch April 19, 2024 09:41
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

3 participants