Feature: add Namer-driven column name lookup in schema field retrieval #7619
+13
−0
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.
What did this pull request do?
Currently,
func (schema *Schema) LookUpField(name string) *Fieldchecks:and returns
nilin the event that the field is not found in either case.This enhances the behavior slightly. The original function is intact, in addition, if a
schema.Namerhas been defined,schema.FieldsByDBNameis checked once more with the namer-driven column name.User Case Description
Admittedly, this is quite self-serving. I've
writtenheavily modified so much that it may as well not be a fork agorm-oracleplugin. One of the many idiosyncrasies of oracle is that it stores all non-quoted, non-reserved-word identifiers asUPPERCASE. This breaks from sanity, logic, good common-sense, most language conventions, and gorm's default handling. If acolumn:tag is set for a field, this value is used (without Namer.ColumnName transformation) exactly as-is if theNamingCaseSensitiveflag is set tofalse. IfNamingCaseSensitiveis set totrue, gorm will quote the exact value of thecolumn:tag. This wouldn't be an issue if oracle treated "foo" and foo the same. But, alas, oracle does not equate "foo" and FOO. However, "FOO" and FOO are considered "same" in oracle-ese. It bears noting that my gorm-oracle plugin provides the necessaryschema.Namerlogic that will handle the proper quote handling of identifiers that must be quoted (reserved words, user-provided quoted identifiers, etc). But without this change, the column metadata returned by oracle (and used by gorm.Scan) will never match thecolumn:foounless the tag is specifiedcolumn:FOO."Why not just use
column:FOO?"Because it's ugly. I don't want to litter my code with
column:SOME_STUPID_UPPER_CASE_NAME. It's also unnecessary to require two different structures for oracle and any other db when one structure would work just fine; if gorm supported it.As an aside, for some weird reason, gorm does not include a "default naming case" option. When
NoLowerCaseis set to true, theDBNamebecomes somethinguselessless-than-useful:UserIDfield name becomesUSERIDin oracle with default gorm. Arguably, this can easily be solved by gorm providing a default case handler:ScreamingSnakeCase,CamelCase(orPascalCasewhichever you prefer), orSnakeCaseor whatever. This would allow users to avoid forcibly setting thecolumn:tag when it otherwise would not have been necessary had gorm provided a means to convert the field name with more precision."Why not just omit
column:altogether and live with gorm's default naming?"No.