zhuxiujia / GoMybatis

Go ORM Library.Have Powerful Features like transaction nesting, Optimistic Lock,Logical deletion and more. like mybatis for go golang
https://zhuxiujia.github.io/gomybatis.io/#/
Apache License 2.0
431 stars 97 forks source link

多数据库如何切换session? #9

Closed pengshaomin closed 5 years ago

zhuxiujia commented 5 years ago

即将支持根据mapper包名路由的动态数据源 的新版本

zhuxiujia commented 5 years ago

No description provided.

新版已增加多数据源和路由支持,详细例子查看https://github.com/zhuxiujia/GoMybatis/blob/master/example/Example_test.go 中的注释

//动态数据源路由
    //GoMybatis.Open("mysql", MysqlUri)//添加第二个mysql数据库,请把MysqlUri改成你的第二个数据源链接
    //var router = GoMybatis.GoMybatisDataSourceRouter{}.New(func(mapperName string) *string {
    //  //根据包名路由指向数据源
    //  if strings.Contains(mapperName, "example.") {
    //      var url = MysqlUri//第二个mysql数据库,请把MysqlUri改成你的第二个数据源链接
    //      fmt.Println(url)
    //      return &url
    //  }
    //  return nil
    //})
    //engine.SetDataSourceRouter(&router)
pengshaomin commented 5 years ago

好的,谢谢回复