@@ -2,8 +2,10 @@ package dolphin
2
2
3
3
import (
4
4
pcast "github.com/pingcap/parser/ast"
5
+ "github.com/pingcap/parser/types"
5
6
6
7
"github.com/kyleconroy/sqlc/internal/sql/ast"
8
+ "github.com/kyleconroy/sqlc/internal/sql/ast/pg"
7
9
)
8
10
9
11
func convertAlterTableStmt (n * pcast.AlterTableStmt ) ast.Node {
@@ -20,9 +22,9 @@ func convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
20
22
Name : & name ,
21
23
Subtype : ast .AT_AddColumn ,
22
24
Def : & ast.ColumnDef {
23
- Colname : def .Name .String (),
24
- // TODO: Use def.Tp to generate type name
25
- TypeName : & ast. TypeName { Name : "text" } ,
25
+ Colname : def .Name .String (),
26
+ TypeName : & ast. TypeName { Name : types . TypeStr ( def .Tp . Tp )},
27
+ IsNotNull : isNotNull ( def ) ,
26
28
},
27
29
})
28
30
}
@@ -61,9 +63,9 @@ func convertCreateTableStmt(n *pcast.CreateTableStmt) ast.Node {
61
63
}
62
64
for _ , def := range n .Cols {
63
65
create .Cols = append (create .Cols , & ast.ColumnDef {
64
- Colname : def .Name .String (),
65
- // TODO: Use n.Tp to generate type name
66
- TypeName : & ast. TypeName { Name : "text" } ,
66
+ Colname : def .Name .String (),
67
+ TypeName : & ast. TypeName { Name : types . TypeStr ( def . Tp . Tp )},
68
+ IsNotNull : isNotNull ( def ) ,
67
69
})
68
70
}
69
71
return create
@@ -78,7 +80,6 @@ func convertDropTableStmt(n *pcast.DropTableStmt) ast.Node {
78
80
}
79
81
80
82
func convertSelectStmt (n * pcast.SelectStmt ) ast.Node {
81
- sel := & ast.SelectStmt {}
82
83
var tables []ast.Node
83
84
visit (n .From , func (n pcast.Node ) {
84
85
name , ok := n .(* pcast.TableName )
@@ -99,9 +100,10 @@ func convertSelectStmt(n *pcast.SelectStmt) ast.Node {
99
100
},
100
101
})
101
102
})
102
- sel .From = & ast.List {Items : tables }
103
- sel .Fields = & ast.List {Items : cols }
104
- return sel
103
+ return & pg.SelectStmt {
104
+ FromClause : & ast.List {Items : tables },
105
+ TargetList : & ast.List {Items : cols },
106
+ }
105
107
}
106
108
107
109
func convert (node pcast.Node ) ast.Node {
0 commit comments