Semaphore/database/mysql.go
2016-03-16 21:49:43 +00:00

30 lines
632 B
Go

package database
import (
"database/sql"
"github.com/ansible-semaphore/semaphore/util"
_ "github.com/go-sql-driver/mysql" // imports mysql driver
"gopkg.in/gorp.v1"
)
var Mysql *gorp.DbMap
// Mysql database
func init() {
url := util.Config.MySQL.Username + ":" + util.Config.MySQL.Password + "@tcp(" + util.Config.MySQL.Hostname + ")/" + util.Config.MySQL.DbName + "?parseTime=true&interpolateParams=true"
db, err := sql.Open("mysql", url)
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
Mysql = &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"}}
}