From 6e470a923910f8d5c021f1a89e867f60f14ecac9 Mon Sep 17 00:00:00 2001 From: Hein Date: Sun, 3 May 2026 17:18:58 +0200 Subject: [PATCH] fix(type_mapper): adjust array tag handling in BuildBunTag --- pkg/writers/bun/type_mapper.go | 2 +- pkg/writers/bun/writer_test.go | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pkg/writers/bun/type_mapper.go b/pkg/writers/bun/type_mapper.go index 54c4fe1..0ca1f57 100644 --- a/pkg/writers/bun/type_mapper.go +++ b/pkg/writers/bun/type_mapper.go @@ -323,7 +323,7 @@ func (tm *TypeMapper) BuildBunTag(column *models.Column, table *models.Table) st } } parts = append(parts, fmt.Sprintf("type:%s", typeStr)) - if isArray { + if isArray && tm.typeStyle == writers.NullableTypeStdlib { parts = append(parts, "array") } } diff --git a/pkg/writers/bun/writer_test.go b/pkg/writers/bun/writer_test.go index 2a203a6..c53a25e 100644 --- a/pkg/writers/bun/writer_test.go +++ b/pkg/writers/bun/writer_test.go @@ -696,7 +696,7 @@ func TestTypeMapper_BuildBunTag(t *testing.T) { Type: "text[]", NotNull: false, }, - want: []string{"tags,", "type:text[],", "array,"}, + want: []string{"tags,", "type:text[],"}, }, { name: "integer array type", @@ -705,7 +705,7 @@ func TestTypeMapper_BuildBunTag(t *testing.T) { Type: "integer[]", NotNull: true, }, - want: []string{"scores,", "type:integer[],", "array,"}, + want: []string{"scores,", "type:integer[],"}, }, } @@ -717,6 +717,30 @@ func TestTypeMapper_BuildBunTag(t *testing.T) { t.Errorf("BuildBunTag() = %q, missing %q", result, part) } } + // resolvespec mode must NOT add "array" — SqlXxxArray uses sql.Scanner + if strings.Contains(result, ",array,") || strings.HasSuffix(result, ",array,") { + t.Errorf("BuildBunTag() = %q, must not contain 'array' in resolvespec mode", result) + } + }) + } +} + +func TestTypeMapper_BuildBunTag_StdlibArrayHasArrayTag(t *testing.T) { + mapper := NewTypeMapper(writers.NullableTypeStdlib) + + cases := []struct { + name string + column *models.Column + }{ + {name: "text array", column: &models.Column{Name: "tags", Type: "text[]"}}, + {name: "integer array", column: &models.Column{Name: "scores", Type: "integer[]", NotNull: true}}, + } + for _, tt := range cases { + t.Run(tt.name, func(t *testing.T) { + result := mapper.BuildBunTag(tt.column, nil) + if !strings.Contains(result, "array") { + t.Errorf("BuildBunTag() = %q, expected 'array' in stdlib mode", result) + } }) } }