func (db *Database) AutoConnect() error {
	var err error
	if db.Ping() == nil {
		return nil
	}
	dsn := model.DSN{
		Driver:   viper.GetString("app.database.driver"),
		Username: viper.GetString("app.database.username"),
		Password: viper.GetString("app.database.password"),
		Hostname: viper.GetString("app.database.host"),
		Port:     viper.GetInt("app.database.port"),
		Name:     viper.GetString("app.database.name"),
	}
	db.Connection, err = gorm.Open(dsn.Driver, dsn.ToString())
	if err != nil {
		return err
	}
	return nil
}
AutoConnect connects to a MySQL database using loaded configs
package module
import (
	"fmt"
	"time"
	"github.com/clivern/beetle/core/migration"
	"github.com/clivern/beetle/core/model"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)
type Database struct {
	Connection *gorm.DB
}
func (db *Database) Connect(dsn model.DSN) error {
	var err error
	if db.Ping() == nil {
		return nil
	}
	db.Connection, err = gorm.Open(dsn.Driver, dsn.ToString())
	if err != nil {
		return err
	}
	return nil
}
func (db *Database) Ping() error {
	if db.Connection == nil {
		return fmt.Errorf("No DB Connections Found")
	}
	err := db.Connection.DB().Ping()
	if err != nil {
		return err
	}
	db.Connection.DB().SetMaxOpenConns(5)
	db.Connection.DB().SetConnMaxLifetime(time.Duration(10) * time.Second)
	dbStats := db.Connection.DB().Stats()
	log.WithFields(log.Fields{
		"dbStats.maxOpenConnections": int(dbStats.MaxOpenConnections),
		"dbStats.openConnections":    int(dbStats.OpenConnections),
		"dbStats.inUse":              int(dbStats.InUse),
		"dbStats.idle":               int(dbStats.Idle),
	}).Debug(`Open DB Connection`)
	return nil
}