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

Support regex for mapping field names #122

Open
jmattheis opened this issue Jan 9, 2024 · 0 comments
Open

Support regex for mapping field names #122

jmattheis opened this issue Jan 9, 2024 · 0 comments
Labels
feature New feature or request

Comments

@jmattheis
Copy link
Owner

When you have fields that are flattened and then prefixed with the nested field name, it would be useful when goverter would support regex.

This example is pretty verbose:

// goverter:map DBObject.ID ID
// goverter:map DBObject.CreatedAt CreatedAt
// goverter:map DBObject.UpdatedAt UpdatedAt
// goverter:map VictoryConditions.NumCriteriaRequired VictoryConditionsNumCriteriaRequired
// goverter:map VictoryConditions.YearsPassed VictoryConditionsYearsPassed
// goverter:map VictoryConditions.OwnPlanets VictoryConditionsOwnPlanets
// goverter:map VictoryConditions.AttainTechLevel VictoryConditionsAttainTechLevel
// goverter:map VictoryConditions.AttainTechLevelNumFields VictoryConditionsAttainTechLevelNumFields
// goverter:map VictoryConditions.ExceedsScore VictoryConditionsExceedsScore
// goverter:map VictoryConditions.ExceedsSecondPlaceScore VictoryConditionsExceedsSecondPlaceScore
// goverter:map VictoryConditions.ProductionCapacity VictoryConditionsProductionCapacity
// goverter:map VictoryConditions.OwnCapitalShips VictoryConditionsOwnCapitalShips
// goverter:map VictoryConditions.HighestScoreAfterYears VictoryConditionsHighestScoreAfterYears
// goverter:map VictoryConditions.Conditions VictoryConditionsConditions
// goverter:map Area.X AreaX
// goverter:map Area.Y AreaY
ConvertGameGame(source *cs.Game) *Game

but with regex this is fairly easy to describe:

// goverter:map:regex DBObject.(\w+) $1
// goverter:map:regex VictoryConditions.(\w+) VictoryConditions$1
// goverter:map:regex Area.(\w+) Area$1
ConvertGameGame(source *cs.Game) *Game

Example from: https://github.com/sirgwain/craig-stars/blob/e3683743518428ee08bf8e63bbf1483f3d1e517f/db/converter.go#L140

Please 👍 this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.

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

No branches or pull requests

1 participant