2019-11-10 08:42:49 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2021-05-21 20:52:03 +00:00
|
|
|
"../../../hotime"
|
2019-11-10 08:42:49 +00:00
|
|
|
"database/sql"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
2021-05-23 21:47:56 +00:00
|
|
|
func SetDB(appIns *hotime.Application, config hotime.Map) {
|
2019-11-10 08:42:49 +00:00
|
|
|
appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
|
2021-05-23 21:47:56 +00:00
|
|
|
query := config.GetString("user") + ":" + config.GetString("password") +
|
|
|
|
"@tcp(" + config.GetString("host") + ":" + config.GetString("port") + ")/" + config.GetString("name") + "?charset=utf8"
|
2019-11-10 08:42:49 +00:00
|
|
|
DB, e := sql.Open("mysql", query)
|
|
|
|
if e != nil && len(err) != 0 {
|
|
|
|
err[0].SetError(e)
|
|
|
|
}
|
|
|
|
return DB
|
|
|
|
})
|
2021-05-23 21:47:56 +00:00
|
|
|
appIns.Db.Type = "mysql"
|
2019-11-10 08:42:49 +00:00
|
|
|
}
|