Add socket support to mysql (#1911)
This commit is contained in:
parent
10ee07cea0
commit
11965f08db
|
@ -89,7 +89,13 @@ func NewClient(config *csconfig.DatabaseCfg) (*Client, error) {
|
||||||
}
|
}
|
||||||
client = ent.NewClient(ent.Driver(drv), entOpt)
|
client = ent.NewClient(ent.Driver(drv), entOpt)
|
||||||
case "mysql":
|
case "mysql":
|
||||||
drv, err := getEntDriver("mysql", dialect.MySQL, fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=True", config.User, config.Password, config.Host, config.Port, config.DbName), config)
|
connString := ""
|
||||||
|
if config.Host == "" && config.Port == 0 && config.DbPath != "" {
|
||||||
|
connString = fmt.Sprintf("%s:%s@unix(%s)/%s?parseTime=True", config.User, config.Password, config.DbPath, config.DbName)
|
||||||
|
} else {
|
||||||
|
connString = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=True", config.User, config.Password, config.Host, config.Port, config.DbName)
|
||||||
|
}
|
||||||
|
drv, err := getEntDriver("mysql", dialect.MySQL, connString, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Client{}, fmt.Errorf("failed opening connection to mysql: %v", err)
|
return &Client{}, fmt.Errorf("failed opening connection to mysql: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue