mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
30 lines
632 B
Go
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"}}
|
|
}
|