From 2ae480556dc660ac3e9b9a5078568e7af7a5847a Mon Sep 17 00:00:00 2001 From: Bharat Patel Date: Thu, 17 Jan 2019 09:56:42 -0800 Subject: [PATCH 1/2] Add DBStats method wrapper to provide sql.DBStats when using ormer --- orm/orm.go | 5 +++++ orm/types.go | 1 + 2 files changed, 6 insertions(+) diff --git a/orm/orm.go b/orm/orm.go index bcf6e4be..b7296ab9 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -522,6 +522,11 @@ func (o *orm) Driver() Driver { return driver(o.alias.Name) } +// return sql.DBStats for current database +func (o *orm) DBStats() sql.DBStats { + return o.alias.DB.Stats() +} + // NewOrm create new orm func NewOrm() Ormer { BootStrap() // execute only once diff --git a/orm/types.go b/orm/types.go index ddf39a2b..4c67c7a6 100644 --- a/orm/types.go +++ b/orm/types.go @@ -128,6 +128,7 @@ type Ormer interface { // // update user testing's name to slene Raw(query string, args ...interface{}) RawSeter Driver() Driver + DBStats() sql.DBStats } // Inserter insert prepared statement From f508f8d959258ecfab3314f0183fc02be755f246 Mon Sep 17 00:00:00 2001 From: Bharat Patel Date: Fri, 18 Jan 2019 16:51:40 -0800 Subject: [PATCH 2/2] Nil check --- orm/orm.go | 9 +++++++-- orm/types.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/orm/orm.go b/orm/orm.go index b7296ab9..fc3cd400 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -523,8 +523,13 @@ func (o *orm) Driver() Driver { } // return sql.DBStats for current database -func (o *orm) DBStats() sql.DBStats { - return o.alias.DB.Stats() +func (o *orm) DBStats() *sql.DBStats { + if o.alias != nil && o.alias.DB != nil { + stats := o.alias.DB.Stats() + return &stats + } + + return nil } // NewOrm create new orm diff --git a/orm/types.go b/orm/types.go index 4c67c7a6..6c6443c7 100644 --- a/orm/types.go +++ b/orm/types.go @@ -128,7 +128,7 @@ type Ormer interface { // // update user testing's name to slene Raw(query string, args ...interface{}) RawSeter Driver() Driver - DBStats() sql.DBStats + DBStats() *sql.DBStats } // Inserter insert prepared statement