Skip to content

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.

2 participants