var Orm *xorm.Engine
func InitMysql() error {
conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
"root", "123456", "192.168.56.3", 3306, "netacl")
orm, err := xorm.NewEngine("mysql", conn)
if err != nil {
return err
}
f, err := os.Create("db.log")
if err != nil {
println(err.Error())
return err
}
orm.SetMaxIdleConns(10)
orm.SetMaxOpenConns(200)
orm.ShowSQL(false)
orm.Logger().SetLevel(core.LOG_DEBUG)
orm.SetLogger(xorm.NewSimpleLogger(f))
err = orm.Ping()
if err != nil {
fmt.Println("连接数据库失败...")
return err
}
fmt.Println("[Connecting MySQL Success!]")
Orm = orm
return nil
}
type AclOrderTag struct {
Acl `xorm:"extends"`
Tag string
}
func test_4() {
res := make([]*AclOrderTag, 0)
_ = Orm.Table("acl_order").Join("INNER", "acl", "acl.order_id = acl_order.id").Where("acl_order.tree_id is NULL").Find(&res)
fmt.Println(res[0])
}
参考:https://xorm.io/zh/docs/chapter-05/5.join/