forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_on.go
More file actions
76 lines (70 loc) · 1.46 KB
/
comment_on.go
File metadata and controls
76 lines (70 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package catalog
import (
"github.com/sqlc-dev/sqlc/internal/sql/ast"
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
)
func (c *Catalog) commentOnColumn(stmt *ast.CommentOnColumnStmt) error {
_, t, err := c.getTable(stmt.Table)
if err != nil {
return err
}
for i := range t.Columns {
if t.Columns[i].Name == stmt.Col.Name {
if stmt.Comment != nil {
t.Columns[i].Comment = *stmt.Comment
} else {
t.Columns[i].Comment = ""
}
return nil
}
}
return sqlerr.ColumnNotFound(stmt.Table.Name, stmt.Col.Name)
}
func (c *Catalog) commentOnSchema(stmt *ast.CommentOnSchemaStmt) error {
s, err := c.getSchema(stmt.Schema.Str)
if err != nil {
return err
}
if stmt.Comment != nil {
s.Comment = *stmt.Comment
} else {
s.Comment = ""
}
return nil
}
func (c *Catalog) commentOnTable(stmt *ast.CommentOnTableStmt) error {
_, t, err := c.getTable(stmt.Table)
if err != nil {
return err
}
if stmt.Comment != nil {
t.Comment = *stmt.Comment
} else {
t.Comment = ""
}
return nil
}
func (c *Catalog) commentOnType(stmt *ast.CommentOnTypeStmt) error {
t, _, err := c.getType(stmt.Type)
if err != nil {
return err
}
if stmt.Comment != nil {
t.SetComment(*stmt.Comment)
} else {
t.SetComment("")
}
return nil
}
func (c *Catalog) commentOnView(stmt *ast.CommentOnViewStmt) error {
_, t, err := c.getTable(stmt.View)
if err != nil {
return err
}
if stmt.Comment != nil {
t.Comment = *stmt.Comment
} else {
t.Comment = ""
}
return nil
}