refactor(writers): simplify model name generation by removing singularization
All checks were successful
CI / Test (1.24) (push) Successful in -25m15s
CI / Test (1.25) (push) Successful in -25m8s
CI / Build (push) Successful in -26m4s
CI / Lint (push) Successful in -25m37s
Integration Tests / Integration Tests (push) Successful in -25m33s
Release / Build and Release (push) Successful in -23m40s
All checks were successful
CI / Test (1.24) (push) Successful in -25m15s
CI / Test (1.25) (push) Successful in -25m8s
CI / Build (push) Successful in -26m4s
CI / Lint (push) Successful in -25m37s
Integration Tests / Integration Tests (push) Successful in -25m33s
Release / Build and Release (push) Successful in -23m40s
This commit is contained in:
@@ -110,8 +110,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
|
|||||||
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
||||||
|
|
||||||
// Generate model name: Model + Schema + Table (all PascalCase)
|
// Generate model name: Model + Schema + Table (all PascalCase)
|
||||||
singularTable := Singularize(table.Name)
|
tablePart := SnakeCaseToPascalCase(table.Name)
|
||||||
tablePart := SnakeCaseToPascalCase(singularTable)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -318,8 +318,7 @@ func (w *Writer) findTable(schemaName, tableName string, db *models.Database) *m
|
|||||||
|
|
||||||
// getModelName generates the model name from schema and table name
|
// getModelName generates the model name from schema and table name
|
||||||
func (w *Writer) getModelName(schemaName, tableName string) string {
|
func (w *Writer) getModelName(schemaName, tableName string) string {
|
||||||
singular := Singularize(tableName)
|
tablePart := SnakeCaseToPascalCase(tableName)
|
||||||
tablePart := SnakeCaseToPascalCase(singular)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
// Verify key elements are present
|
// Verify key elements are present
|
||||||
expectations := []string{
|
expectations := []string{
|
||||||
"package models",
|
"package models",
|
||||||
"type ModelPublicUser struct",
|
"type ModelPublicUsers struct",
|
||||||
"bun.BaseModel",
|
"bun.BaseModel",
|
||||||
"table:public.users",
|
"table:public.users",
|
||||||
"alias:users",
|
"alias:users",
|
||||||
@@ -78,9 +78,9 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
"resolvespec_common.SqlTime",
|
"resolvespec_common.SqlTime",
|
||||||
"bun:\"id",
|
"bun:\"id",
|
||||||
"bun:\"email",
|
"bun:\"email",
|
||||||
"func (m ModelPublicUser) TableName() string",
|
"func (m ModelPublicUsers) TableName() string",
|
||||||
"return \"public.users\"",
|
"return \"public.users\"",
|
||||||
"func (m ModelPublicUser) GetID() int64",
|
"func (m ModelPublicUsers) GetID() int64",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, expected := range expectations {
|
for _, expected := range expectations {
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
|
|||||||
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
||||||
|
|
||||||
// Generate model name: Model + Schema + Table (all PascalCase)
|
// Generate model name: Model + Schema + Table (all PascalCase)
|
||||||
singularTable := Singularize(table.Name)
|
tablePart := SnakeCaseToPascalCase(table.Name)
|
||||||
tablePart := SnakeCaseToPascalCase(singularTable)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -312,8 +312,7 @@ func (w *Writer) findTable(schemaName, tableName string, db *models.Database) *m
|
|||||||
|
|
||||||
// getModelName generates the model name from schema and table name
|
// getModelName generates the model name from schema and table name
|
||||||
func (w *Writer) getModelName(schemaName, tableName string) string {
|
func (w *Writer) getModelName(schemaName, tableName string) string {
|
||||||
singular := Singularize(tableName)
|
tablePart := SnakeCaseToPascalCase(tableName)
|
||||||
tablePart := SnakeCaseToPascalCase(singular)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
// Verify key elements are present
|
// Verify key elements are present
|
||||||
expectations := []string{
|
expectations := []string{
|
||||||
"package models",
|
"package models",
|
||||||
"type ModelPublicUser struct",
|
"type ModelPublicUsers struct",
|
||||||
"ID",
|
"ID",
|
||||||
"int64",
|
"int64",
|
||||||
"Email",
|
"Email",
|
||||||
@@ -75,9 +75,9 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
"time.Time",
|
"time.Time",
|
||||||
"gorm:\"column:id",
|
"gorm:\"column:id",
|
||||||
"gorm:\"column:email",
|
"gorm:\"column:email",
|
||||||
"func (m ModelPublicUser) TableName() string",
|
"func (m ModelPublicUsers) TableName() string",
|
||||||
"return \"public.users\"",
|
"return \"public.users\"",
|
||||||
"func (m ModelPublicUser) GetID() int64",
|
"func (m ModelPublicUsers) GetID() int64",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, expected := range expectations {
|
for _, expected := range expectations {
|
||||||
|
|||||||
Reference in New Issue
Block a user