feat(pkg): preserve PostgreSQL types in mapDataType function
* Add support for known PostgreSQL types and modifiers * Implement canonicalization for PostgreSQL types * Introduce unit tests for PostgreSQL type handling
This commit is contained in:
@@ -493,3 +493,55 @@ func TestRelationships(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapDataType_PostgresTypes(t *testing.T) {
|
||||
reader := &Reader{}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
inputType string
|
||||
size int
|
||||
wantType string
|
||||
wantLength int
|
||||
}{
|
||||
{
|
||||
name: "integer array preserved",
|
||||
inputType: "integer[]",
|
||||
wantType: "integer[]",
|
||||
},
|
||||
{
|
||||
name: "citext array preserved",
|
||||
inputType: "citext[]",
|
||||
wantType: "citext[]",
|
||||
},
|
||||
{
|
||||
name: "vector modifier preserved",
|
||||
inputType: "vector(1536)",
|
||||
wantType: "vector(1536)",
|
||||
},
|
||||
{
|
||||
name: "alias canonicalized in array",
|
||||
inputType: "int4[]",
|
||||
wantType: "integer[]",
|
||||
},
|
||||
{
|
||||
name: "varchar length from size",
|
||||
inputType: "varchar",
|
||||
size: 120,
|
||||
wantType: "varchar",
|
||||
wantLength: 120,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotType, gotLength := reader.mapDataType(tt.inputType, tt.size)
|
||||
if gotType != tt.wantType {
|
||||
t.Fatalf("mapDataType(%q, %d) type = %q, want %q", tt.inputType, tt.size, gotType, tt.wantType)
|
||||
}
|
||||
if gotLength != tt.wantLength {
|
||||
t.Fatalf("mapDataType(%q, %d) length = %d, want %d", tt.inputType, tt.size, gotLength, tt.wantLength)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user