Skip to content
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

关于orm优雅配置问题 #38

Open
ZhuRongGo opened this issue Aug 6, 2021 · 2 comments
Open

关于orm优雅配置问题 #38

ZhuRongGo opened this issue Aug 6, 2021 · 2 comments

Comments

@ZhuRongGo
Copy link

问题:在orm.go 文件中,如何优雅的配置,连接多数据库,读写分离,求解
场景:在生产环境,会出现读写分离,多数据库场景
1、db_user库下user表
2、db_order库下order表

请教一下,希望得到解答

@qloog
Copy link
Contributor

qloog commented Aug 7, 2021

关于连接多数据库有两种解决方案:
1、db_user和db_order在配置上分开,然后通过orm.NewMySQL来实例化到两个全局变量上,最后分开调用即可;
2、封装两个方法,例如 orm.Init()orm.Get(), orm.Init() 支持初始化多个数据库,内部放入到全局map里,orm.Get() 获取时从map获取db实例
目前是第一种可以直接使用,第二种需要做一层简单封装,现在框架还没做这一块。
@webff

@qloog
Copy link
Contributor

qloog commented Dec 24, 2023

目前已经支持 多数据库配置。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants