feat: add SQLConnector
This commit is contained in:
parent
740f2be453
commit
8c92f70527
4
gorm.go
4
gorm.go
@ -375,6 +375,10 @@ func (db *DB) AddError(err error) error {
|
|||||||
func (db *DB) DB() (*sql.DB, error) {
|
func (db *DB) DB() (*sql.DB, error) {
|
||||||
connPool := db.ConnPool
|
connPool := db.ConnPool
|
||||||
|
|
||||||
|
if connector, ok := connPool.(SQLConnector); ok && connector != nil {
|
||||||
|
return connector.GetSQLConn(db)
|
||||||
|
}
|
||||||
|
|
||||||
if dbConnector, ok := connPool.(GetDBConnector); ok && dbConnector != nil {
|
if dbConnector, ok := connPool.(GetDBConnector); ok && dbConnector != nil {
|
||||||
return dbConnector.GetDBConn()
|
return dbConnector.GetDBConn()
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,12 @@ type GetDBConnector interface {
|
|||||||
GetDBConn() (*sql.DB, error)
|
GetDBConn() (*sql.DB, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQLConnector represents SQL db connector which takes into account the current
|
||||||
|
// database context
|
||||||
|
type SQLConnector interface {
|
||||||
|
GetSQLConn(db *DB) (*sql.DB, error)
|
||||||
|
}
|
||||||
|
|
||||||
// Rows rows interface
|
// Rows rows interface
|
||||||
type Rows interface {
|
type Rows interface {
|
||||||
Columns() ([]string, error)
|
Columns() ([]string, error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user