objection.js icon indicating copy to clipboard operation
objection.js copied to clipboard

Feature request: make knexSnakeCaseMappers behavior with multiple consecutive uppercase letters configurable

Open brianmcd opened this issue 6 years ago • 2 comments

First off, thanks so much for your work on Objection. It's really a great piece of work.

The issue I'm running into is that the current knexSnakeCaseMappers implementation converts strings like isALevel to is_alevel, isBLevel to is_blevel, etc. This means that if you have a column like is_a_level or is_b_level, you can't access it when using knexSnakeCaseMappers (as far as I can tell, at least). isBLevel and isBlevel both get mapped to the same thing: is_blevel.

It looks like the code adds a special case for when there are two or more consecutive uppercase letters here: https://github.com/Vincit/objection.js/blob/5b76a4c1e0dee70649d32b8a59383021bb5d5927/lib/utils/identifierMapping.js#L55-L61

Would it make sense to add a parameter to disable this special case, similar to how you handled underscoreBeforeDigits? https://github.com/Vincit/objection.js/blob/5b76a4c1e0dee70649d32b8a59383021bb5d5927/lib/utils/identifierMapping.js#L24

brianmcd avatar Feb 07 '20 14:02 brianmcd

The reason for the current behavior is acronyms like isORM, which should usually be mapped to is_orm. But your case makes sense too. Let's add an option for this. What would be a good name for this? underscoreBetweenUppercaseLetters?

koskimas avatar Feb 07 '20 18:02 koskimas

Awesome, thanks! underscoreBetweenUppercaseLetters sounds like a good name to me.

brianmcd avatar Feb 07 '20 19:02 brianmcd