Skip to content

Commit fcfa8a4

Browse files
orisanokyleconroy
andauthored
feat: add supporting COMMENT ON VIEW (sqlc-dev#2249)
* feat: add supporting COMMENT ON VIEW close sqlc-dev#2241 * test: Add tests for COMMENT ON VIEW --------- Co-authored-by: Kyle Conroy <kyle@conroy.org>
1 parent 090cb54 commit fcfa8a4

File tree

15 files changed

+152
-0
lines changed

15 files changed

+152
-0
lines changed

internal/endtoend/testdata/comment_on/postgresql/pgx/v4/go/models.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/comment_on/postgresql/pgx/v4/query.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ CREATE TABLE foo.bar (
44
baz text NOT NULL
55
);
66

7+
CREATE VIEW foo.bat AS SELECT * FROM foo.bar;
8+
79
CREATE TYPE foo.mood AS ENUM ('sad', 'ok', 'happy');
810

911
COMMENT ON SCHEMA foo IS 'this is the foo schema';
1012
COMMENT ON TYPE foo.mood IS 'this is the mood type';
1113
COMMENT ON TABLE foo.bar IS 'this is the bar table';
1214
COMMENT ON COLUMN foo.bar.baz IS 'this is the baz column';
15+
COMMENT ON VIEW foo.bat IS 'this is the bat view ';
1316

1417
-- name: ListBar :many
1518
SELECT * FROM foo.bar;
19+
20+
-- name: ListBat :many
21+
SELECT * FROM foo.bat;

internal/endtoend/testdata/comment_on/postgresql/pgx/v5/go/models.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ CREATE TABLE foo.bar (
44
baz text NOT NULL
55
);
66

7+
CREATE VIEW foo.bat AS SELECT * FROM foo.bar;
8+
79
CREATE TYPE foo.mood AS ENUM ('sad', 'ok', 'happy');
810

911
COMMENT ON SCHEMA foo IS 'this is the foo schema';
1012
COMMENT ON TYPE foo.mood IS 'this is the mood type';
1113
COMMENT ON TABLE foo.bar IS 'this is the bar table';
1214
COMMENT ON COLUMN foo.bar.baz IS 'this is the baz column';
15+
COMMENT ON VIEW foo.bat IS 'this is the bat view ';
1316

1417
-- name: ListBar :many
1518
SELECT * FROM foo.bar;
19+
20+
-- name: ListBat :many
21+
SELECT * FROM foo.bat;

internal/endtoend/testdata/comment_on/postgresql/stdlib/go/models.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/comment_on/postgresql/stdlib/go/query.sql.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/comment_on/postgresql/stdlib/query.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ CREATE TABLE foo.bar (
44
baz text NOT NULL
55
);
66

7+
CREATE VIEW foo.bat AS SELECT * FROM foo.bar;
8+
79
CREATE TYPE foo.mood AS ENUM ('sad', 'ok', 'happy');
810

911
COMMENT ON SCHEMA foo IS 'this is the foo schema';
1012
COMMENT ON TYPE foo.mood IS 'this is the mood type';
1113
COMMENT ON TABLE foo.bar IS 'this is the bar table';
1214
COMMENT ON COLUMN foo.bar.baz IS 'this is the baz column';
15+
COMMENT ON VIEW foo.bat IS 'this is the bat view ';
1316

1417
-- name: ListBar :many
1518
SELECT * FROM foo.bar;
19+
20+
-- name: ListBat :many
21+
SELECT * FROM foo.bat;

internal/engine/postgresql/parse.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,16 @@ func translate(node *nodes.Node) (ast.Node, error) {
379379
Comment: makeString(n.Comment),
380380
}, nil
381381

382+
case nodes.ObjectType_OBJECT_VIEW:
383+
rel, err := parseRelation(n.Object)
384+
if err != nil {
385+
return nil, fmt.Errorf("COMMENT ON VIEW: %w", err)
386+
}
387+
return &ast.CommentOnViewStmt{
388+
View: rel.TableName(),
389+
Comment: makeString(n.Comment),
390+
}, nil
391+
382392
}
383393
return nil, errSkip
384394

0 commit comments

Comments
 (0)