Skip to content

Commit 3de2337

Browse files
committed
Fixed datatype documentation
1 parent f4cef4d commit 3de2337

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

docs/reference/datatypes.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
## Arrays
44

55
PostgreSQL [arrays](https://www.postgresql.org/docs/current/arrays.html) are
6-
materialized as Go slices. Currently, only one-dimensional arrays are
7-
supported.
6+
materialized as Go slices. Currently, the `pgx/v5` sql package only supports multidimensional arrays.
87

98
```sql
109
CREATE TABLE places (
@@ -26,6 +25,7 @@ type Place struct {
2625

2726
All PostgreSQL time and date types are returned as `time.Time` structs. For
2827
null time or date values, the `NullTime` type from `database/sql` is used.
28+
The `pgx/v5` sql package uses the appropriate pgx types.
2929

3030
```sql
3131
CREATE TABLE authors (
@@ -86,7 +86,7 @@ type Store struct {
8686
## Null
8787

8888
For structs, null values are represented using the appropriate type from the
89-
`database/sql` package.
89+
`database/sql` or `pgx` package.
9090

9191
```sql
9292
CREATE TABLE authors (
@@ -132,3 +132,48 @@ type Author struct {
132132
ID uuid.UUID
133133
}
134134
```
135+
136+
## JSON
137+
138+
By default, sqlc will generate the `[]byte`, `pgtype.JSON` or `json.RawMessage` for JSON column type.
139+
But if you use the `pgx/v5` sql package then you can specify a some struct instead of default type.
140+
The `pgx` implementation will marshall/unmarshall the struct automatically.
141+
142+
```go
143+
package dto
144+
145+
type BookData struct {
146+
Genres []string `json:"genres"`
147+
Title string `json:"title"`
148+
Published bool `json:"published"`
149+
}
150+
```
151+
152+
```sql
153+
CREATE TABLE books (
154+
data jsonb
155+
);
156+
```
157+
158+
```json
159+
{
160+
"overrides": [
161+
{
162+
"column": "books.data",
163+
"go_type": "*example.com/db/dto.BookData"
164+
}
165+
]
166+
}
167+
```
168+
169+
```go
170+
package db
171+
172+
import (
173+
"example.com/db/dto"
174+
)
175+
176+
type Book struct {
177+
Data *dto.BookData
178+
}
179+
```

0 commit comments

Comments
 (0)