go-gorm / sharding

High performance table sharding plugin for Gorm.
MIT License
272 stars 59 forks source link

fix: support sharding sql with alias in where clause #32

Open a631807682 opened 2 years ago

a631807682 commented 2 years ago

What did this pull request do?

When we use db.Preload, it will generate sql with alias like:

SELECT * FROM "orders" WHERE "orders"."user_id" = 1

The expr parsed by sql is sqlparser.QualifiedRef which is not supported and will return ErrMissingShardingKey This feat will replace sql like this:

SELECT * FROM "orders_1" as "orders" WHERE "orders"."user_id" = 1

User Case Description

a631807682 commented 2 years ago

related to https://github.com/go-gorm/gorm/pull/5301 will not panic in next gorm version test will pass when https://github.com/go-gorm/sharding/pull/34 merged.

ifooth commented 1 year ago

Any Update?, Support for the sqlparser.QualifiedRef feature is quite needed