Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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