Back to Gorm Io

Generic database interface sql.DB

pages/ar_SA/docs/generic_interface.md

latest684 B
Original Source

GORM provides the method DB which returns a generic database interface *sql.DB from the current *gorm.DB

go
// Get generic database object sql.DB to use its functions
sqlDB, err := db.DB()

// Ping
sqlDB. Ping()

// Close
sqlDB. Close()

// Returns database statistics
sqlDB. Stats()

{% note warn %} NOTE If the underlying database connection is not a *sql.DB, like in a transaction, it will returns error {% endnote %}

Connection Pool

go
// Get generic database object sql.DB to use its functions
sqlDB, err := db.DB()

// Ping
sqlDB.
Ping()

// Close
sqlDB.
Close()

// Returns database statistics
sqlDB.
Stats()