Commit ead63822 by mushishixian

多数据库配置

parent 3cb876c1
[gorm]
mode = debug
[mysql] [mysql]
user_name = root user_name = root
password = root password = root
host = 192.168.2.239 host = 192.168.2.250
database = test database = test1
table_prefix = table_prefix =
type = mysql type = mysql
......
...@@ -46,12 +46,14 @@ func Setup() error { ...@@ -46,12 +46,14 @@ func Setup() error {
} }
DatabaseConMap[conName].DB().SetMaxIdleConns(db.MaxIdleCons) DatabaseConMap[conName].DB().SetMaxIdleConns(db.MaxIdleCons)
DatabaseConMap[conName].DB().SetMaxOpenConns(db.MaxOpenCons) DatabaseConMap[conName].DB().SetMaxOpenConns(db.MaxOpenCons)
DatabaseConMap[conName].LogMode(true) if config.Get("gorm.mode").String() == "debug" {
DatabaseConMap[conName].LogMode(true)
}
} }
return nil return nil
} }
func GetDB(conName string) *gorm.DB { func Connection(conName string) *gorm.DB {
return DatabaseConMap[conName] return DatabaseConMap[conName]
} }
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"search_server/boot" "search_server/boot"
"search_server/pkg/config"
"search_server/pkg/mysql" "search_server/pkg/mysql"
) )
...@@ -15,15 +14,20 @@ func main() { ...@@ -15,15 +14,20 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
//fmt.Println(model.GetExcludeBrandIds(1)) type Result struct {
fmt.Println(config.GetSectionValues("supplier_all")) BinId int `json:"bin_id"`
fmt.Println(config.Cfg.Section("xxx").Key("xxx")) Bin string `json:"bin"`
res, _ := mysql.GetDB("mysql").Exec("SELECT * FROM lie_bin").Rows() }
fmt.Println(res) var result []Result
mysql.Connection("bom").Raw("SELECT * FROM lie_bin").Scan(&result)
//client := client. //mysql.Connection()("bom").Table("bin").Find(&result)
//c := course.NewCourseService("go.micro.api.jtthink.course", client) fmt.Println(result)
//course_rsp, _ := c.ListForTop(context.TODO(), &course.ListRequest{Size: 10})
//fmt.Println(course_rsp.Result)
type Result2 struct {
BusinessName string `json:"business_name"`
}
var result2 []Result2
mysql.Connection("mysql").Raw("SELECT * FROM lie_business").Scan(&result2)
//mysql.GetDB("bom").Table("bin").Find(&result)
fmt.Println(result2)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment