gen icon indicating copy to clipboard operation
gen copied to clipboard

fix: Can only init once for the same *gorm.DB

Open jiekun opened this issue 1 year ago • 3 comments

  • [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.

jiekun avatar Sep 21 '22 12:09 jiekun

gen.WithDefaultQuery generate code with a default global variable Q as a singleton. demo

qqxhb avatar Sep 21 '22 12:09 qqxhb

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.

jiekun avatar Sep 21 '22 12:09 jiekun

BTW do we support multiple databases (like master and slave *gorm.DB) by the defaultQuery way?

jiekun avatar Sep 21 '22 12:09 jiekun