@@ -8,51 +8,52 @@ import (
88 "strings"
99)
1010
11- func makeComments (ctx context.Context , conn PgGoConnection , model interface {}) error {
12- modelType := reflect .TypeOf (model )
13- var tableName pg.Safe
11+ func makeComments (ctx context.Context , conn PgGoConnection , models ... interface {}) error {
12+ for _ , model := range models {
13+ modelType := reflect .TypeOf (model )
14+ var tableName pg.Safe
15+
16+ for i := 0 ; i < modelType .NumField (); i ++ {
17+ fieldType := modelType .Field (i )
18+
19+ if fieldType .Name == "tableName" {
20+ var ok bool
21+ tableName , ok = getPgName (fieldType )
22+ if ! ok {
23+ tableName = pg .Safe (hasura .ToSnakeCase (modelType .Name ()))
24+ }
25+
26+ pgCommentTag , ok := getPgComment (fieldType )
27+ if ! ok {
28+ continue
29+ }
30+
31+ if _ , err := conn .DB ().ExecContext (ctx ,
32+ `COMMENT ON TABLE ? IS ?` ,
33+ tableName , pgCommentTag ); err != nil {
34+ return err
35+ }
1436
15- for i := 0 ; i < modelType .NumField (); i ++ {
16- fieldType := modelType .Field (i )
17-
18- if fieldType .Name == "tableName" {
19- var ok bool
20- tableName , ok = getPgName (fieldType )
21- if ! ok {
22- tableName = pg .Safe (hasura .ToSnakeCase (modelType .Name ()))
37+ continue
2338 }
2439
2540 pgCommentTag , ok := getPgComment (fieldType )
2641 if ! ok {
2742 continue
2843 }
2944
45+ columnName , ok := getPgName (fieldType )
46+ if ! ok {
47+ columnName = pg .Safe (hasura .ToSnakeCase (fieldType .Name ))
48+ }
49+
3050 if _ , err := conn .DB ().ExecContext (ctx ,
31- `COMMENT ON TABLE ? IS ?` ,
32- tableName , pgCommentTag ); err != nil {
51+ `COMMENT ON COLUMN ?. ? IS ?` ,
52+ tableName , columnName , pgCommentTag ); err != nil {
3353 return err
3454 }
35-
36- continue
37- }
38-
39- pgCommentTag , ok := getPgComment (fieldType )
40- if ! ok {
41- continue
42- }
43-
44- columnName , ok := getPgName (fieldType )
45- if ! ok {
46- columnName = pg .Safe (hasura .ToSnakeCase (fieldType .Name ))
47- }
48-
49- if _ , err := conn .DB ().ExecContext (ctx ,
50- `COMMENT ON COLUMN ?.? IS ?` ,
51- tableName , columnName , pgCommentTag ); err != nil {
52- return err
5355 }
5456 }
55-
5657 return nil
5758}
5859
0 commit comments