Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for embedded structs #582

Closed
wants to merge 3 commits into from

Conversation

duckbrain
Copy link
Contributor

@duckbrain duckbrain commented Aug 14, 2020

Closes #351

Currently, pop treats embedded structs as a distinct field (like the reflection package exposes). sqlx, which binds the values out of the struct treats the embedded fields as if on the parent (like the language makes appear to happen).

This checks for a newly introduced inline option to the db flag in the struct tags and inlines a struct (embedded or not), so that that struct's fields are included as if part of the parent object.

  • db:",inline" or db:"-,inline" will inline the struct, but not include the field
  • db:"name,inline"will include all of the fields on the struct, and the struct itself as the name field.
  • db:"name"will include the struct as the name field. (Useful for struct types that implement Valuer and Scanner.)

This preserves the previous behavior by default, but allows embedded structs to be ignored as well.

@duckbrain duckbrain requested a review from a team as a code owner August 14, 2020 23:25
@duckbrain duckbrain marked this pull request as draft August 15, 2020 02:12
Matches encoding/json and encoding/xml term
@duckbrain duckbrain marked this pull request as ready for review August 15, 2020 15:37
@duckbrain duckbrain closed this Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow embedding structs for a common columns
1 participant