Skip to content

Commit 425e284

Browse files
committed
More Format
1 parent 3c17e93 commit 425e284

8 files changed

Lines changed: 54 additions & 2 deletions

File tree

internal/endtoend/fmt_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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)

internal/sql/ast/case_expr.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ type CaseExpr struct {
1313
func (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+
}

internal/sql/ast/case_when.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ type CaseWhen struct {
1010
func (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+
}

internal/sql/ast/listen_stmt.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ type ListenStmt struct {
77
func (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+
}

internal/sql/ast/notify_stmt.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@ type NotifyStmt struct {
88
func (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+
}

internal/sql/ast/null.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ type Null struct {
66
func (n *Null) Pos() int {
77
return 0
88
}
9+
func (n *Null) Format(buf *TrackedBuffer) {
10+
buf.WriteString("NULL")
11+
}

internal/sql/ast/res_target.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

internal/sql/ast/type_name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)