From f508f8d959258ecfab3314f0183fc02be755f246 Mon Sep 17 00:00:00 2001 From: Bharat Patel Date: Fri, 18 Jan 2019 16:51:40 -0800 Subject: [PATCH] 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