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

Introduce additional casing strategies. #7

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

fr33r
Copy link
Collaborator

@fr33r fr33r commented Mar 14, 2025

Description

These changes introduce support for the following column casing strategies:

  • screaming snake case (EXAMPLE_COLUMN_NAME)
  • uppercase (EXAMPLECOLUMNNAME)
  • lowercase (examplecolumnname)

It additionally supports screaming snake case for table names.

NOTE: it's important to use the same specified casing when using the WithPrimaryKeyColumn or WithPrimaryKeyColumns options.

Rationale

While less common, these casing strategies for columns and tables do occur.

Suggested Version

v1.2.0

Example Usage

obj = ...

// uppercase column names.
options := []morph.ReflectOptions{
  morph.WithInferredColumnNames(morph.UpperCaseStrategy),
  moprh.WithPrimaryKeyColumn("ID"),
}
table, err := morph.Reflect(obj, options...)
if err != nil {
  panic(err)
}

// lowercase column names.
options := []morph.ReflectOptions{
  morph.WithInferredColumnNames(morph.LowerCaseStrategy),
  moprh.WithPrimaryKeyColumn("id"),
}
table, err := morph.Reflect(obj, options...)
if err != nil {
  panic(err)
}

// screaming snake case column names.
options := []morph.ReflectOptions{
  morph.WithInferredColumnNames(morph.ScreamingSnakeCaseStrategy),
  moprh.WithPrimaryKeyColumn("ID"),
}
table, err := morph.Reflect(obj, options...)
if err != nil {
  panic(err)
}

@fr33r fr33r marked this pull request as ready for review March 14, 2025 06:38
@fr33r fr33r merged commit 8d48591 into master Mar 14, 2025
4 checks passed
@fr33r fr33r self-assigned this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant