gen
gen copied to clipboard
fix: Can only init once for the same *gorm.DB
- [x] Do only one thing
- [x] Non breaking API changes
- [x] Tested
What did this pull request do?
Fixed https://github.com/go-gorm/gen/issues/653
User Case Description
See https://github.com/go-gorm/gen/issues/653
Upgrade Guide
For the user who calls query.Use()
to generate *query.Query
before each query call, and use Table()
method to specific table name, please consider this fix to avoid table name cache by GORM.
gen.WithDefaultQuery
generate code with a default global variable Q as a singleton.
demo
I think this still needs to be fixed. We refer README.md
and follow the query.Use
way to write our codes.
More importantly, it's hard to know what Q
means. And user can call query.Use
for multiple times.
I cannot imagine the necessity of allowing this. Users who call it twice might receive an unexpected result.
BTW do we support multiple databases (like master and slave *gorm.DB) by the defaultQuery
way?