-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gdb.DB: I want dongtai change current db,thanks! #4223
Comments
我猜你想找这个
https://github.com/gogf/gf/blob/master/database/gdb/gdb_model.go |
我想全局改,而不是每次都是手动去调用这个 DB方法,请问除了修改 gf gen dao 的模板,还有其他法子吗? |
你应该是saas的效果,a账号下面的系统,发送请求到a数据库,b账号下面的系统,发送请求时到b数据库吧? |
You should have the effect of saas, the system under account a send request to database a, the system under account b, the system under account b, the system under account b, when sending request, right? |
是的,我想要全局动态的去切数据库,你有什么好的解决方案吗? |
Yes, I want to cut the database dynamically globally. Do you have any good solutions? |
我想全局动态切换呢,每次手动去调用分库逻辑的话肯定会发生遗漏的情况,您给的这个页面最下面我看到有人也提出了这样的问题,现在生成的 gf gen dao 把数据库链接写死了,能不能开个自定义的口子,让用户可以去设置当前的db |
I want to switch globally dynamically. Every time I manually call the library logic, there will definitely be omissions. At the bottom of the page you gave me, I saw someone raise this question. The generated gf gen dao has written the database link to death. Can you open a custom hole so that users can set the current db |
那就按评论,自己写dao就可以了,模板生成只是比较简单的一种方式。 |
Then just follow the comments and write it yourself. Template generation is just a relatively simple way. |
func (dao *GenTableDao) DBTenant(ctx context.Context) gdb.DB { func (dao *GenTableDao) Ctx(ctx context.Context) *gdb.Model { getDb方法:获取中间件的的租户db名称 |
func (dao *GenTableDao) DBTenant(ctx context.Context) gdb.DB { func (dao *GenTableDao) Ctx(ctx context.Context) *gdb.Model { getDb method: get the middleware's tenant db name |
Is your feature request related to a problem?
Option Yes
Describe the solution you'd like
gdb.DB:我想动态的去切换当前的数据库,现在 gf gen dao 生成出来的
func (dao *SysDictDao) DB() gdb.DB { return g.DB(dao.group) }
数据库是固定死的,不支持动态的切换,我有几个同样的数据库,这里我想动态的去切换数据库(或者 sass系统也需要这个方案),希望这里可以加一个可以自定义获取 db的方法,谢谢!Describe alternatives you've considered
1
Additional
No response
The text was updated successfully, but these errors were encountered: