1 Star 0 Fork 0

ichub / goconfig

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
db_client_dto.go 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
leijmdas 提交于 2024-05-05 12:24 . add
package baseconfig
import (
"fmt"
"gitee.com/ichub/goconfig/common/base/baseconsts"
)
type DbClientDto struct {
IchubClientDto `json:"-"`
Dbtype string `json:"dbtype"`
Dbname string `json:"dbname"`
Host string `json:"host"`
Port string `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Sslmode string `json:"sslmode"`
Charset string `json:"charset"`
GormClient *GormClientDto `json:"gorm_client"`
}
func NewDbClientDto() *DbClientDto {
var dbClient = &DbClientDto{}
dbClient.InitProxy(dbClient)
return dbClient
}
func (this *DbClientDto) MakeMysqlUrl() string {
return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&mb4&parseTime=True&loc=Local",
this.Username, this.Password, this.Host, this.Port, this.Dbname)
}
func (this *DbClientDto) MakePostgresUrl() string {
return fmt.Sprintf("postgresql://%s:%s@tcp(%s:%s)/%s?charset=utf8&mb4&parseTime=True&loc=Local&sslmode=%s",
this.Username, this.Password, this.Host, this.Port, this.Dbname, this.Sslmode)
}
func (this *DbClientDto) MakeCockroachUrl() string {
return fmt.Sprintf("postgresql://%s:%s@tcp(%s:%s)/%s?charset=utf8&mb4&parseTime=True&loc=Local&sslmode=%s",
this.Username, this.Password, this.Host, this.Port, this.Dbname, this.Sslmode)
}
func (this *DbClientDto) IsMysql() bool {
return this.Dbtype == baseconsts.DB_TYPE_MYSQL
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ichub/goconfig.git
git@gitee.com:ichub/goconfig.git
ichub
goconfig
goconfig
v1.0.407

搜索帮助