Skip to content

Model structs in models.go vs. MyFooRow #667

Answered by kyleconroy
markschmid asked this question in General
Discussion options

You must be logged in to vote

You're correct. The generated code will only return Person structs if you've selected all fields from the person table. If you select a sub-set of those fields, sqlc will create a query-specific struct to return.

At first I thought, this library (which I still like) helps to circumvent having to work with the sql.NullXY datatypes.

sqlc provides a thin wrapper on top of your data model. That means that you'll need to handle NULL values and cases where you've written queries that return incomplete data. My suggestion is to have a separate set of structs that you return in your API instead of returning the database models directly. This layer of indirection allows you to change your databa…

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@markschmid
Comment options

Answer selected by kyleconroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #667 on August 23, 2020 19:55.