Skip to content

Commit 0e7fa5a

Browse files
kyleconroyclaude
andcommitted
refactor(postgresql): use existing convert functions instead of translate helpers
Replace custom translate functions (translateTypeNameFromPG, translateOptions, translateNode, translateDefElem) with existing convert.go functions (convertTypeName, convertSlice) to maintain architectural consistency. Both parse.go and convert.go import the same pg_query_go/v6 package, so the types are compatible and the existing convert functions can be used directly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c4e885f commit 0e7fa5a

File tree

1 file changed

+2
-90
lines changed

1 file changed

+2
-90
lines changed

internal/engine/postgresql/parse.go

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -34,94 +34,6 @@ func stringSliceFromNodes(s []*nodes.Node) []string {
3434
return items
3535
}
3636

37-
func translateNode(node *nodes.Node) ast.Node {
38-
if node == nil {
39-
return nil
40-
}
41-
switch n := node.Node.(type) {
42-
case *nodes.Node_String_:
43-
return &ast.String{Str: n.String_.Sval}
44-
case *nodes.Node_Integer:
45-
return &ast.Integer{Ival: int64(n.Integer.Ival)}
46-
case *nodes.Node_Boolean:
47-
return &ast.Boolean{Boolval: n.Boolean.Boolval}
48-
case *nodes.Node_AConst:
49-
// A_Const contains a constant value (used in type modifiers like varchar(32))
50-
if n.AConst.GetIval() != nil {
51-
return &ast.Integer{Ival: int64(n.AConst.GetIval().Ival)}
52-
}
53-
if n.AConst.GetSval() != nil {
54-
return &ast.String{Str: n.AConst.GetSval().Sval}
55-
}
56-
if n.AConst.GetFval() != nil {
57-
return &ast.Float{Str: n.AConst.GetFval().Fval}
58-
}
59-
if n.AConst.GetBoolval() != nil {
60-
return &ast.Boolean{Boolval: n.AConst.GetBoolval().Boolval}
61-
}
62-
return &ast.TODO{}
63-
case *nodes.Node_List:
64-
list := &ast.List{}
65-
for _, item := range n.List.Items {
66-
list.Items = append(list.Items, translateNode(item))
67-
}
68-
return list
69-
default:
70-
return &ast.TODO{}
71-
}
72-
}
73-
74-
func translateDefElem(n *nodes.DefElem) *ast.DefElem {
75-
if n == nil {
76-
return nil
77-
}
78-
defname := n.Defname
79-
return &ast.DefElem{
80-
Defname: &defname,
81-
Arg: translateNode(n.Arg),
82-
Location: int(n.Location),
83-
}
84-
}
85-
86-
func translateOptions(opts []*nodes.Node) *ast.List {
87-
if opts == nil {
88-
return nil
89-
}
90-
list := &ast.List{}
91-
for _, opt := range opts {
92-
if de, ok := opt.Node.(*nodes.Node_DefElem); ok {
93-
list.Items = append(list.Items, translateDefElem(de.DefElem))
94-
}
95-
}
96-
return list
97-
}
98-
99-
func translateTypeNameFromPG(tn *nodes.TypeName) *ast.TypeName {
100-
if tn == nil {
101-
return nil
102-
}
103-
rel, err := parseRelationFromNodes(tn.Names)
104-
if err != nil {
105-
return nil
106-
}
107-
result := rel.TypeName()
108-
// Preserve array bounds
109-
if len(tn.ArrayBounds) > 0 {
110-
result.ArrayBounds = &ast.List{}
111-
for _, ab := range tn.ArrayBounds {
112-
result.ArrayBounds.Items = append(result.ArrayBounds.Items, translateNode(ab))
113-
}
114-
}
115-
// Preserve type modifiers
116-
if len(tn.Typmods) > 0 {
117-
result.Typmods = &ast.List{}
118-
for _, tm := range tn.Typmods {
119-
result.Typmods.Items = append(result.Typmods.Items, translateNode(tm))
120-
}
121-
}
122-
return result
123-
}
124-
12537
type relation struct {
12638
Catalog string
12739
Schema string
@@ -528,7 +440,7 @@ func translate(node *nodes.Node) (ast.Node, error) {
528440

529441
create.Cols = append(create.Cols, &ast.ColumnDef{
530442
Colname: item.ColumnDef.Colname,
531-
TypeName: translateTypeNameFromPG(item.ColumnDef.TypeName),
443+
TypeName: convertTypeName(item.ColumnDef.TypeName),
532444
IsNotNull: isNotNull(item.ColumnDef) || primaryKey[item.ColumnDef.Colname],
533445
IsArray: isArray(item.ColumnDef.TypeName),
534446
ArrayDims: len(item.ColumnDef.TypeName.ArrayBounds),
@@ -577,7 +489,7 @@ func translate(node *nodes.Node) (ast.Node, error) {
577489
ReturnType: rt,
578490
Replace: n.Replace,
579491
Params: &ast.List{},
580-
Options: translateOptions(n.Options),
492+
Options: convertSlice(n.Options),
581493
}
582494
for _, item := range n.Parameters {
583495
arg := item.Node.(*nodes.Node_FunctionParameter).FunctionParameter

0 commit comments

Comments
 (0)