File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99 "testing"
1010
1111 pg_query "github.com/pganalyze/pg_query_go/v4"
12+ "github.com/sqlc-dev/sqlc/internal/debug"
1213 "github.com/sqlc-dev/sqlc/internal/engine/postgresql"
1314 "github.com/sqlc-dev/sqlc/internal/sql/ast"
1415)
@@ -63,6 +64,7 @@ func TestFormat(t *testing.T) {
6364 t .Error (err )
6465 }
6566 if expected != actual {
67+ debug .Dump (stmts [0 ].Raw )
6668 t .Errorf ("- %s" , expected )
6769 t .Errorf ("- %s" , string (query ))
6870 t .Errorf ("+ %s" , actual )
Original file line number Diff line number Diff line change @@ -13,3 +13,14 @@ type CaseExpr struct {
1313func (n * CaseExpr ) Pos () int {
1414 return n .Location
1515}
16+
17+ func (n * CaseExpr ) Format (buf * TrackedBuffer ) {
18+ if n == nil {
19+ return
20+ }
21+ buf .WriteString ("CASE " )
22+ buf .astFormat (n .Args )
23+ buf .WriteString (" ELSE " )
24+ buf .astFormat (n .Defresult )
25+ buf .WriteString (" END " )
26+ }
Original file line number Diff line number Diff line change @@ -10,3 +10,13 @@ type CaseWhen struct {
1010func (n * CaseWhen ) Pos () int {
1111 return n .Location
1212}
13+
14+ func (n * CaseWhen ) Format (buf * TrackedBuffer ) {
15+ if n == nil {
16+ return
17+ }
18+ buf .WriteString ("WHEN " )
19+ buf .astFormat (n .Expr )
20+ buf .WriteString (" THEN " )
21+ buf .astFormat (n .Result )
22+ }
Original file line number Diff line number Diff line change @@ -7,3 +7,13 @@ type ListenStmt struct {
77func (n * ListenStmt ) Pos () int {
88 return 0
99}
10+
11+ func (n * ListenStmt ) Format (buf * TrackedBuffer ) {
12+ if n == nil {
13+ return
14+ }
15+ buf .WriteString ("LISTEN " )
16+ if n .Conditionname != nil {
17+ buf .WriteString (* n .Conditionname )
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -8,3 +8,18 @@ type NotifyStmt struct {
88func (n * NotifyStmt ) Pos () int {
99 return 0
1010}
11+
12+ func (n * NotifyStmt ) Format (buf * TrackedBuffer ) {
13+ if n == nil {
14+ return
15+ }
16+ buf .WriteString ("NOTIFY " )
17+ if n .Conditionname != nil {
18+ buf .WriteString (* n .Conditionname )
19+ }
20+ if n .Payload != nil {
21+ buf .WriteString (", '" )
22+ buf .WriteString (* n .Payload )
23+ buf .WriteString ("'" )
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -6,3 +6,6 @@ type Null struct {
66func (n * Null ) Pos () int {
77 return 0
88}
9+ func (n * Null ) Format (buf * TrackedBuffer ) {
10+ buf .WriteString ("NULL" )
11+ }
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ func (n *ResTarget) Format(buf *TrackedBuffer) {
1515 if n == nil {
1616 return
1717 }
18+ buf .astFormat (n .Val )
1819 if n .Name != nil {
20+ buf .WriteString (" AS " )
1921 buf .WriteString (* n .Name )
2022 }
21- buf .astFormat (n .Val )
2223}
Original file line number Diff line number Diff line change @@ -24,5 +24,5 @@ func (n *TypeName) Format(buf *TrackedBuffer) {
2424 if n == nil {
2525 return
2626 }
27- buf .astFormat (n .Names )
27+ buf .join (n .Names , "." )
2828}
You can’t perform that action at this time.
0 commit comments