fix(cmd/gendao): fix overlapping shardingPattern matching issue#4631
Merged
gqcn merged 1 commit intogogf:masterfrom Jan 21, 2026
Merged
Conversation
When shardingPattern contains overlapping prefixes like ["a_?", "a_b_?", "a_c_?"], tables like "a_b_1" would incorrectly match "a_?" instead of the more specific "a_b_?" pattern. Changes: - Sort shardingPattern by length descending so longer patterns match first - Add break after successful pattern match to prevent multiple matches This ensures tables are matched by the most specific (longest) pattern.
gqcn
approved these changes
Jan 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
When
shardingPatterncontains overlapping prefixes like["a_?", "a_b_?", "a_c_?"]:a_b_1,a_b_2should matcha_b_?and generatea_b.goa_c_1,a_c_2should matcha_c_?and generatea_c.goa_1,a_2should matcha_?and generatea.goBut without this fix,
a_?(converted to regexa_(.+)) would matcha_b_1first, causinga_b_?anda_c_?patterns to fail to generate their respective dao files.Solution
shardingPatternby length descending before matchingbreakafter a table matches a pattern to prevent multiple matchesTest plan
Test_Gen_Dao_Sharding_Overlappingwith overlapping patternssharding_overlapping.sqla.go,a_b.go,a_c.goFixes #4603