refactor(writers): simplify model name generation by removing singularization

This commit is contained in:
2026-02-08 14:50:39 +02:00
parent 466d657ea7
commit bcf54336cb
6 changed files with 10 additions and 14 deletions

View File

@@ -110,8 +110,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
// Generate model name: Model + Schema + Table (all PascalCase)
singularTable := Singularize(table.Name)
tablePart := SnakeCaseToPascalCase(singularTable)
tablePart := SnakeCaseToPascalCase(table.Name)
// Include schema name in model name
var modelName string

View File

@@ -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
func (w *Writer) getModelName(schemaName, tableName string) string {
singular := Singularize(tableName)
tablePart := SnakeCaseToPascalCase(singular)
tablePart := SnakeCaseToPascalCase(tableName)
// Include schema name in model name
var modelName string

View File

@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
// Verify key elements are present
expectations := []string{
"package models",
"type ModelPublicUser struct",
"type ModelPublicUsers struct",
"bun.BaseModel",
"table:public.users",
"alias:users",
@@ -78,9 +78,9 @@ func TestWriter_WriteTable(t *testing.T) {
"resolvespec_common.SqlTime",
"bun:\"id",
"bun:\"email",
"func (m ModelPublicUser) TableName() string",
"func (m ModelPublicUsers) TableName() string",
"return \"public.users\"",
"func (m ModelPublicUser) GetID() int64",
"func (m ModelPublicUsers) GetID() int64",
}
for _, expected := range expectations {

View File

@@ -109,8 +109,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
// Generate model name: Model + Schema + Table (all PascalCase)
singularTable := Singularize(table.Name)
tablePart := SnakeCaseToPascalCase(singularTable)
tablePart := SnakeCaseToPascalCase(table.Name)
// Include schema name in model name
var modelName string

View File

@@ -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
func (w *Writer) getModelName(schemaName, tableName string) string {
singular := Singularize(tableName)
tablePart := SnakeCaseToPascalCase(singular)
tablePart := SnakeCaseToPascalCase(tableName)
// Include schema name in model name
var modelName string

View File

@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
// Verify key elements are present
expectations := []string{
"package models",
"type ModelPublicUser struct",
"type ModelPublicUsers struct",
"ID",
"int64",
"Email",
@@ -75,9 +75,9 @@ func TestWriter_WriteTable(t *testing.T) {
"time.Time",
"gorm:\"column:id",
"gorm:\"column:email",
"func (m ModelPublicUser) TableName() string",
"func (m ModelPublicUsers) TableName() string",
"return \"public.users\"",
"func (m ModelPublicUser) GetID() int64",
"func (m ModelPublicUsers) GetID() int64",
}
for _, expected := range expectations {