Skip to content

Commit fe5d5c3

Browse files
committed
fmt
1 parent f566907 commit fe5d5c3

14 files changed

Lines changed: 144 additions & 39 deletions

File tree

internal/endtoend/testdata/join_where_clause/postgresql/pgx/v5/query.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ WHERE owner = $1;
1414
SELECT foo.*
1515
FROM foo
1616
CROSS JOIN bar
17-
WHERE bar.id = $2 AND owner = $1;
17+
WHERE bar.id = $2 AND owner = $1;

internal/endtoend/testdata/materialized_views/postgresql/pgx/v4/go/query.sql.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
CREATE TABLE authors (
2-
id BIGSERIAL PRIMARY KEY,
3-
name TEXT NOT NULL,
4-
bio TEXT
5-
);
6-
7-
ALTER TABLE authors ADD COLUMN gender INTEGER NULL;
8-
9-
CREATE MATERIALIZED VIEW authors_names as SELECT name from authors;
10-
1+
-- name: ListAuthors :many
112
SELECT * FROM authors;

internal/endtoend/testdata/materialized_views/postgresql/pgx/v5/go/query.sql.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
CREATE TABLE authors (
2-
id BIGSERIAL PRIMARY KEY,
3-
name TEXT NOT NULL,
4-
bio TEXT
5-
);
6-
7-
ALTER TABLE authors ADD COLUMN gender INTEGER NULL;
8-
9-
CREATE MATERIALIZED VIEW authors_names as SELECT name from authors;
10-
1+
-- name: ListAuthors :many
112
SELECT * FROM authors;
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
CREATE TABLE authors (
2-
id BIGSERIAL PRIMARY KEY,
3-
name TEXT NOT NULL,
4-
bio TEXT
5-
);
6-
7-
ALTER TABLE authors ADD COLUMN gender INTEGER NULL;
8-
9-
CREATE MATERIALIZED VIEW authors_names as SELECT name from authors;
10-
1+
-- name: ListAuthors :many
112
SELECT * FROM authors;

internal/engine/postgresql/convert.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,7 @@ func convertNode(node *pg.Node) ast.Node {
36433643
return convertXmlSerialize(n.XmlSerialize)
36443644

36453645
default:
3646+
fmt.Printf("todo: %T\n", n)
36463647
return &ast.TODO{}
36473648
}
36483649
}

internal/engine/postgresql/parse.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,21 @@ func translate(node *nodes.Node) (ast.Node, error) {
438438
if err != nil {
439439
return nil, err
440440
}
441+
442+
primary := false
443+
for _, con := range item.ColumnDef.Constraints {
444+
if constraint, ok := con.Node.(*nodes.Node_Constraint); ok {
445+
primary = constraint.Constraint.Contype == nodes.ConstrType_CONSTR_PRIMARY
446+
}
447+
}
448+
441449
create.Cols = append(create.Cols, &ast.ColumnDef{
442-
Colname: item.ColumnDef.Colname,
443-
TypeName: rel.TypeName(),
444-
IsNotNull: isNotNull(item.ColumnDef) || primaryKey[item.ColumnDef.Colname],
445-
IsArray: isArray(item.ColumnDef.TypeName),
446-
ArrayDims: len(item.ColumnDef.TypeName.ArrayBounds),
450+
Colname: item.ColumnDef.Colname,
451+
TypeName: rel.TypeName(),
452+
IsNotNull: isNotNull(item.ColumnDef) || primaryKey[item.ColumnDef.Colname],
453+
IsArray: isArray(item.ColumnDef.TypeName),
454+
ArrayDims: len(item.ColumnDef.TypeName.ArrayBounds),
455+
PrimaryKey: primary,
447456
})
448457
}
449458
}

internal/sql/ast/alter_table_cmd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,17 @@ type AlterTableCmd struct {
3939
func (n *AlterTableCmd) Pos() int {
4040
return 0
4141
}
42+
43+
func (n *AlterTableCmd) Format(buf *TrackedBuffer) {
44+
if n == nil {
45+
return
46+
}
47+
switch n.Subtype {
48+
case AT_AddColumn:
49+
buf.WriteString(" ADD COLUMN ")
50+
case AT_DropColumn:
51+
buf.WriteString(" DROP COLUMN ")
52+
}
53+
54+
buf.astFormat(n.Def)
55+
}

internal/sql/ast/alter_table_stmt.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ type AlterTableStmt struct {
1212
func (n *AlterTableStmt) Pos() int {
1313
return 0
1414
}
15+
16+
func (n *AlterTableStmt) Format(buf *TrackedBuffer) {
17+
if n == nil {
18+
return
19+
}
20+
buf.WriteString("ALTER TABLE ")
21+
buf.astFormat(n.Relation)
22+
buf.astFormat(n.Table)
23+
buf.astFormat(n.Cmds)
24+
}

0 commit comments

Comments
 (0)