InfoSphere/GORM 中文版/ 返回书籍
Tutorials

Generic database interface sql.DB

qianmoQqianmoQ· 更新于 2026-09-15· 阅读 2 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

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


sqlDB, err := db.DB()


sqlDB.Ping()


sqlDB.Close()


sqlDB.Stats()

NOTE If the underlying database connection is not a *sql.DB, like in a transaction, it will returns error

Connection Pool


sqlDB, err := db.DB()


sqlDB.SetMaxIdleConns(10)


sqlDB.SetMaxOpenConns(100)


sqlDB.SetConnMaxLifetime(time.Hour)

GitHub tag (latest SemVer)

评论

登录后参与评论

正在加载评论…