Merge pull request #1045 from tomcatzh/master

Add mysql unix socket support.
tokarchuk/v1.17
无闻 10 years ago
commit 8238c28c31
  1. 9
      models/models.go

@ -89,8 +89,13 @@ func getEngine() (*xorm.Engine, error) {
cnnstr := "" cnnstr := ""
switch DbCfg.Type { switch DbCfg.Type {
case "mysql": case "mysql":
cnnstr = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", if DbCfg.Host[0] == '/' { // looks like a unix socket
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name) cnnstr = fmt.Sprintf("%s:%s@unix(%s)/%s?charset=utf8",
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name)
} else {
cnnstr = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name)
}
case "postgres": case "postgres":
var host, port = "127.0.0.1", "5432" var host, port = "127.0.0.1", "5432"
fields := strings.Split(DbCfg.Host, ":") fields := strings.Split(DbCfg.Host, ":")

Loading…
Cancel
Save