Skip to content

Commit bf7e8ee

Browse files
Merge pull request #66 from oracle-samples/json-support
Adding docs for json columns handling
2 parents 485cace + 2dc911b commit bf7e8ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ BEGIN
7979
END;
8080
```
8181

82+
### JSON Columns
83+
84+
Use either JSON type—both fully support `INSERT`, `UPDATE`, and `DELETE``RETURNING`:
85+
86+
- `gorm.io/datatypes.JSON` — convenient for logging/printing; returned as text then rewrapped.
87+
- `encoding/json.RawMessage` — raw `[]byte` fast-path; ideal for large payloads or minimal decoding.
88+
89+
#### Notes:
90+
- On multi-row `RETURNING`, we use PL/SQL bulk blocks and map results back into your structs.
91+
- `datatypes.JSON` comes back as text; `json.RawMessage` comes back as bytes.
92+
93+
Take the following struct as an example:
94+
95+
```go
96+
type Record struct {
97+
ID uint `gorm:"primaryKey;autoIncrement;column:record_id"`
98+
Name string `gorm:"column:name"`
99+
// Text-oriented JSON
100+
Properties datatypes.JSON `gorm:"column:properties"`
101+
// Raw bytes JSON
102+
Payload json.RawMessage `gorm:"column:payload"`
103+
}
104+
```
105+
82106
## Contributing
83107

84108
This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md)

0 commit comments

Comments
 (0)