mirror of https://github.com/go-gorm/gorm.git
feat: add *sql.DB connector that uses database context (#6366)
* feat: add SQLConnector * rename
This commit is contained in:
parent
5eaccaa624
commit
661781a3d7
4
gorm.go
4
gorm.go
|
@ -375,6 +375,10 @@ func (db *DB) AddError(err error) error {
|
|||
func (db *DB) DB() (*sql.DB, error) {
|
||||
connPool := db.ConnPool
|
||||
|
||||
if connector, ok := connPool.(GetDBConnectorWithContext); ok && connector != nil {
|
||||
return connector.GetDBConnWithContext(db)
|
||||
}
|
||||
|
||||
if dbConnector, ok := connPool.(GetDBConnector); ok && dbConnector != nil {
|
||||
if sqldb, err := dbConnector.GetDBConn(); sqldb != nil || err != nil {
|
||||
return sqldb, err
|
||||
|
|
|
@ -77,6 +77,12 @@ type GetDBConnector interface {
|
|||
GetDBConn() (*sql.DB, error)
|
||||
}
|
||||
|
||||
// GetDBConnectorWithContext represents SQL db connector which takes into
|
||||
// account the current database context
|
||||
type GetDBConnectorWithContext interface {
|
||||
GetDBConnWithContext(db *DB) (*sql.DB, error)
|
||||
}
|
||||
|
||||
// Rows rows interface
|
||||
type Rows interface {
|
||||
Columns() ([]string, error)
|
||||
|
|
Loading…
Reference in New Issue