refactor(pkg): canonicalize base types and adjust length handling
* Update base types to keep explicit modifier forms * Modify length handling for vector types in tests
This commit is contained in:
@@ -711,6 +711,7 @@ func (r *Reader) parseTypeWithLength(typeStr string) (baseType string, length in
|
||||
rawBaseType := strings.TrimSpace(matches[1])
|
||||
if pgsql.SupportsLength(rawBaseType) {
|
||||
if _, err := fmt.Sscanf(matches[2], "%d", &length); err == nil {
|
||||
baseType = pgsql.CanonicalizeBaseType(rawBaseType)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,9 +367,9 @@ func TestParseTypeWithLength_PreservesExplicitTypeModifiers(t *testing.T) {
|
||||
wantType string
|
||||
wantLength int
|
||||
}{
|
||||
{"varchar(255)", "varchar(255)", 255},
|
||||
{"character varying(120)", "character varying(120)", 120},
|
||||
{"vector(1536)", "vector(1536)", 1536},
|
||||
{"varchar(255)", "varchar", 255},
|
||||
{"character varying(120)", "character varying", 120},
|
||||
{"vector(1536)", "vector(1536)", 0},
|
||||
{"numeric(10,2)", "numeric(10,2)", 0},
|
||||
}
|
||||
|
||||
|
||||
@@ -317,7 +317,7 @@ func TestConvertToColumn_PreservesExplicitTypeModifiers(t *testing.T) {
|
||||
name: "custom vector modifier",
|
||||
fieldType: "vector(1536)",
|
||||
wantType: "vector(1536)",
|
||||
wantLength: 1536,
|
||||
wantLength: 0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -804,6 +804,7 @@ func (r *Reader) parseTypeWithLength(typeStr string) (baseType string, length in
|
||||
// This avoids converting custom modifiers like vector(1536) into Length.
|
||||
if pgsql.SupportsLength(rawBaseType) && !strings.Contains(parens, ",") {
|
||||
if _, err := fmt.Sscanf(parens, "%d", &length); err == nil {
|
||||
baseType = pgsql.CanonicalizeBaseType(rawBaseType)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,9 +374,9 @@ func TestParseTypeWithLength_PreservesExplicitTypeModifiers(t *testing.T) {
|
||||
wantType string
|
||||
wantLength int
|
||||
}{
|
||||
{"varchar(255)", "varchar(255)", 255},
|
||||
{"character varying(120)", "character varying(120)", 120},
|
||||
{"vector(1536)", "vector(1536)", 1536},
|
||||
{"varchar(255)", "varchar", 255},
|
||||
{"character varying(120)", "character varying", 120},
|
||||
{"vector(1536)", "vector(1536)", 0},
|
||||
{"numeric(10,2)", "numeric(10,2)", 0},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user