How do I tell sqlc to omit a field in the json if it's empty #1087
Unanswered
adityaladwa asked this question in Q&A
Replies: 3 comments 4 replies
-
There is currently not a way a to do this. What you can do is use a custom struct and override the output of the query to return that struct. |
Beta Was this translation helpful? Give feedback.
4 replies
-
In the same vein, could sql add support for golang json struct flag type User struct { Id int64 `json:"id,string"` } |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have opened a PR for adding support for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have a table
After I run
sqlc generate
the following model will be generated:I would like to omit the description if it's empty (as it's a nullable column).
Now, I can use column override and use
string
type instead ofsql.NullString
. So now the generated type will beThe problem with this is that if Description is
nil
, it won't be omitted from thejson
response. So the response would be something like this:Is there a way I can tell
sqlc
to addomitempty
tag to a particular field? (Description field in this case)Any other way to solve this issue?
Beta Was this translation helpful? Give feedback.
All reactions