You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto/rename.md
+26-3Lines changed: 26 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,14 +30,22 @@ sql:
30
30
31
31
## Tables
32
32
33
-
The output structs associated with tables can also be renamed. By default, the struct name will be the singular version of the table name. For example, the `authors` table will generate an `Author` struct.
33
+
The output structs associated with tables can also be renamed. By default,
34
+
the struct name will be the singular version of the table name. For example,
35
+
the `authors` table will generate an `Author` struct and the `book_publishers`
36
+
table will generate a `BookPublisher` struct.
34
37
35
38
```sql
36
39
CREATE TABLE authors (
37
40
id BIGSERIAL PRIMARY KEY,
38
41
name text NOT NULL,
39
42
bio text
40
43
);
44
+
45
+
CREATE TABLE book_publishers (
46
+
id BIGSERIAL PRIMARY KEY,
47
+
name text NOT NULL
48
+
);
41
49
```
42
50
43
51
```go
@@ -52,9 +60,17 @@ type Author struct {
52
60
Name string
53
61
Bio sql.NullString
54
62
}
63
+
64
+
type Publisher struct {
65
+
ID int64
66
+
Name string
67
+
}
55
68
```
56
69
57
-
To rename this struct, you must use the generated struct name. In this example, that would be `author`. Use the `rename` map to change the name of this struct to `Writer` (note the uppercase `W`).
70
+
To rename these structs, you must use the generated struct name. In this
71
+
example, that would be `author` and `book_publisher`. Use the `rename` map to
72
+
change the name of these struct to `Writer` and `BookPublisher` (note the
73
+
camel-casing and the underscore for multi-worded tables).
58
74
59
75
```yaml
60
76
version: '1'
@@ -65,6 +81,7 @@ packages:
65
81
queries: query.sql
66
82
rename:
67
83
author: Writer
84
+
book_publisher: Publisher
68
85
```
69
86
70
87
```yaml
@@ -77,6 +94,7 @@ overrides:
77
94
go:
78
95
rename:
79
96
author: Writer
97
+
book_publisher: Publisher
80
98
```
81
99
82
100
```go
@@ -91,9 +109,14 @@ type Writer struct {
91
109
Name string
92
110
Bio sql.NullString
93
111
}
112
+
113
+
type Publisher struct {
114
+
ID int64
115
+
Name string
116
+
}
94
117
```
95
118
96
119
## Limitations
97
120
98
121
Rename mappings apply to an entire package. Therefore, a column named `foo` and
99
-
a table name `foo` can't map to different rename values.
122
+
a table name `foo` can't map to different rename values.
0 commit comments