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: README.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -272,6 +272,7 @@ type ATable struct {
272
272
unexported int// Unexported field is not visible to Struct.
273
273
Quotedstring`db:"quoted" fieldopt:"withquote"`// Add quote to the field using back quote or double quote. See `Flavor#Quote`.
274
274
Emptyuint`db:"empty" fieldopt:"omitempty"`// Omit the field in UPDATE if it is a nil or zero value.
275
+
PayloadMeta`db:"payload" fieldopt:"noexpand"`// Treat a nested struct as one column instead of expanding it.
275
276
276
277
// The `omitempty` can be written as a function.
277
278
// In this case, omit empty field `Tagged` when UPDATE for tag `tag1` and `tag3` but not `tag2`.
@@ -311,6 +312,27 @@ fmt.Println(sql)
311
312
// SELECT post.id, post.text, comment.body FROM posts post JOIN comments comment ON post.id = comment.post_id
312
313
```
313
314
315
+
If a nested struct should stay as a single column, add `fieldopt:"noexpand"` to opt out of the automatic expansion. This is useful for JSON columns scanned into Go structs by the database driver.
For detailed instructions on utilizing `Struct`, refer to the [examples](https://pkg.go.dev/github.com/huandu/go-sqlbuilder#Struct).
315
337
316
338
Furthermore, `Struct` can be employed as a zero-configuration ORM. Unlike most ORM implementations that necessitate preliminary configurations for database connectivity, `Struct` operates without any configuration, functioning seamlessly with any SQL driver compatible with `database/sql`. `Struct` does not invoke any `database/sql` APIs; it solely generates the appropriate SQL statements with arguments for `DB#Query`/`DB#Exec` or an array of struct field addresses for `Rows#Scan`/`Row#Scan`.
0 commit comments