MCPcopy
hub / github.com/go-gorm/gorm / DB

Method DB

gorm.go:426–446  ·  view source on GitHub ↗

DB returns `*sql.DB`

()

Source from the content-addressed store, hash-verified

424
425// DB returns `*sql.DB`
426func (db *DB) DB() (*sql.DB, error) {
427 connPool := db.ConnPool
428 if db.Statement != nil && db.Statement.ConnPool != nil {
429 connPool = db.Statement.ConnPool
430 }
431 if tx, ok := connPool.(*sql.Tx); ok && tx != nil {
432 return (*sql.DB)(reflect.ValueOf(tx).Elem().FieldByName("db").UnsafePointer()), nil
433 }
434
435 if dbConnector, ok := connPool.(GetDBConnector); ok && dbConnector != nil {
436 if sqldb, err := dbConnector.GetDBConn(); sqldb != nil || err != nil {
437 return sqldb, err
438 }
439 }
440
441 if sqldb, ok := connPool.(*sql.DB); ok && sqldb != nil {
442 return sqldb, nil
443 }
444
445 return nil, ErrInvalidDB
446}
447
448func (db *DB) getInstance() *DB {
449 if db.clone > 0 {

Callers 5

OpenFunction · 0.80
ConnectionMethod · 0.80
TestPreparedStmtDeadlockFunction · 0.80
initFunction · 0.80

Calls 1

GetDBConnMethod · 0.65

Tested by 3

TestPreparedStmtDeadlockFunction · 0.64
initFunction · 0.64