Skip to content

feat: add *sql.DB connector that uses database context #6366

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

Merged
merged 2 commits into from
Jun 5, 2023

Conversation

lzakharov
Copy link
Contributor

@lzakharov lzakharov commented May 31, 2023

  • Do only one thing
  • Non breaking API changes
  • Tested (looks unnecessary)

What did this pull request do?

This PR adds ability to provide *sql.DB connector which can resolve current connect based on the database context. It works the same as GetDBConnector but additionally have *gorm.DB state.

User Case Description

Since we use DBResolver plugin to provide multiple databases support, sometimes it's necessary to get raw *sql.DB. 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()

However, it seems to us more logical behavior to return different connections based on the current database state.

@lzakharov lzakharov changed the title feat: add SQLConnector feat: add *sql.DB connector that uses database context Jun 1, 2023
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.

4 participants