fix(writer): update nullable type handling to use baselib

* change default nullable type from resolvespec to baselib
* update type mappings in tests to reflect new nullable types
* adjust comments for clarity on nullable type options
This commit is contained in:
2026-06-25 23:25:36 +02:00
parent e29c7e31c1
commit ab735d1f3a
8 changed files with 128 additions and 40 deletions
+19 -19
View File
@@ -73,9 +73,9 @@ func TestWriter_WriteTable(t *testing.T) {
"ID",
"int64",
"Email",
"resolvespec_common.SqlString",
"*string",
"CreatedAt",
"resolvespec_common.SqlTime",
"time.Time",
"bun:\"id",
"bun:\"email",
"func (m ModelPublicUsers) TableName() string",
@@ -564,20 +564,20 @@ func TestTypeMapper_SQLTypeToGoType_Bun(t *testing.T) {
want string
}{
{"bigint", true, "int64"},
{"bigint", false, "resolvespec_common.SqlInt64"},
{"varchar", true, "resolvespec_common.SqlString"}, // Bun uses sql types even for NOT NULL strings
{"varchar", false, "resolvespec_common.SqlString"},
{"timestamp", true, "resolvespec_common.SqlTimeStamp"},
{"timestamp", false, "resolvespec_common.SqlTimeStamp"},
{"date", false, "resolvespec_common.SqlDate"},
{"bigint", false, "*int64"},
{"varchar", true, "string"},
{"varchar", false, "*string"},
{"timestamp", true, "time.Time"},
{"timestamp", false, "*time.Time"},
{"date", false, "*time.Time"},
{"boolean", true, "bool"},
{"boolean", false, "resolvespec_common.SqlBool"},
{"uuid", false, "resolvespec_common.SqlUUID"},
{"jsonb", false, "resolvespec_common.SqlJSONB"},
{"text[]", true, "resolvespec_common.SqlStringArray"},
{"text[]", false, "resolvespec_common.SqlStringArray"},
{"integer[]", true, "resolvespec_common.SqlInt32Array"},
{"bigint[]", false, "resolvespec_common.SqlInt64Array"},
{"boolean", false, "*bool"},
{"uuid", false, "*string"},
{"jsonb", false, "*string"},
{"text[]", true, "[]string"},
{"text[]", false, "[]string"},
{"integer[]", true, "[]int32"},
{"bigint[]", false, "[]int64"},
}
for _, tt := range tests {
@@ -599,7 +599,7 @@ func TestWriter_UpdateIDTypeSafety_Bun(t *testing.T) {
forbidInt32 bool
}{
{"int32_pk", "int", "int32", "m.ID = int32(newid)", false},
{"sql_int16_pk", "smallint", "resolvespec_common.SqlInt16", "m.ID.FromString(fmt.Sprintf(\"%d\", newid))", true},
{"sql_int16_pk", "smallint", "int16", "m.ID = int16(newid)", true},
{"int64_pk", "bigint", "int64", "m.ID = int64(newid)", true},
}
@@ -680,13 +680,13 @@ func TestWriter_StringPrimaryKeyHelpers_Bun(t *testing.T) {
generated := string(content)
expectations := []string{
"resolvespec_common.SqlUUID",
"ID string",
"func (m ModelPublicAccounts) GetID() string",
"return m.ID.String()",
"return m.ID",
"func (m ModelPublicAccounts) GetIDStr() string",
"func (m ModelPublicAccounts) SetID(newid string)",
"func (m *ModelPublicAccounts) UpdateID(newid string)",
"m.ID.FromString(newid)",
"m.ID = newid",
}
for _, expected := range expectations {