Commit ead63822 by mushishixian

多数据库配置

parent 3cb876c1
[gorm]
mode = debug
[mysql]
user_name = root
password = root
host = 192.168.2.239
database = test
host = 192.168.2.250
database = test1
table_prefix =
type = mysql
......
......@@ -46,12 +46,14 @@ func Setup() error {
}
DatabaseConMap[conName].DB().SetMaxIdleConns(db.MaxIdleCons)
DatabaseConMap[conName].DB().SetMaxOpenConns(db.MaxOpenCons)
DatabaseConMap[conName].LogMode(true)
if config.Get("gorm.mode").String() == "debug" {
DatabaseConMap[conName].LogMode(true)
}
}
return nil
}
func GetDB(conName string) *gorm.DB {
func Connection(conName string) *gorm.DB {
return DatabaseConMap[conName]
}
......@@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"search_server/boot"
"search_server/pkg/config"
"search_server/pkg/mysql"
)
......@@ -15,15 +14,20 @@ func main() {
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
//fmt.Println(model.GetExcludeBrandIds(1))
fmt.Println(config.GetSectionValues("supplier_all"))
fmt.Println(config.Cfg.Section("xxx").Key("xxx"))
res, _ := mysql.GetDB("mysql").Exec("SELECT * FROM lie_bin").Rows()
fmt.Println(res)
//client := client.
//c := course.NewCourseService("go.micro.api.jtthink.course", client)
//course_rsp, _ := c.ListForTop(context.TODO(), &course.ListRequest{Size: 10})
//fmt.Println(course_rsp.Result)
type Result struct {
BinId int `json:"bin_id"`
Bin string `json:"bin"`
}
var result []Result
mysql.Connection("bom").Raw("SELECT * FROM lie_bin").Scan(&result)
//mysql.Connection()("bom").Table("bin").Find(&result)
fmt.Println(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