func (db *Database) GetJobs() []model.Job {
	jobs := []model.Job{}
	db.Connection.Select("*").Find(&jobs)
	return jobs
}
GetJobs gets jobs
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
}
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
}
func (db *Database) Migrate() bool {
	status := true
	db.Connection.AutoMigrate(&migration.Job{})
	status = status && db.Connection.HasTable(&migration.Job{})
	return status
}
func (db *Database) Rollback() bool {
	status := true
	db.Connection.DropTableIfExists(&migration.Job{})
	status = status && !db.Connection.HasTable(&migration.Job{})
	return status
}
func (db *Database) HasTable(table string) bool {
	return db.Connection.HasTable(table)
}
func (db *Database) CreateJob(job *model.Job) *model.Job {
	db.Connection.Create(job)
	return job
}
func (db *Database) JobExistByID(id int) bool {
	job := model.Job{}
	db.Connection.Where("id = ?", id).First(&job)
	return job.ID > 0
}
func (db *Database) GetJobByID(id int) model.Job {
	job := model.Job{}
	db.Connection.Where("id = ?", id).First(&job)
	return job
}