Use model struct as method parameter #875
Unanswered
maratori asked this question in Feature Requests & Ideas
Replies: 4 comments 3 replies
-
Hi. Has anything become of this idea? |
BetaWas this translation helpful?Give feedback.
3 replies
-
Seems like a flag in -- name: PersistNewCity :entity :oneINSERT INTO city ( * ) VALUES ( ** ) RETURNING *;results in func (q*Queries) PersistNewCity(ctx context.Context, argCity) (City, error){where expands |
BetaWas this translation helpful?Give feedback.
0 replies
-
+1 How do maintainers feel about it? We can probably help open a PR |
BetaWas this translation helpful?Give feedback.
0 replies
-
We really need it |
BetaWas this translation helpful?Give feedback.
0 replies
Sign up for freeto 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.
-
Some of insert queries contains all columns of table as input parameters.
In that case generated method may apply model struct instead of
...Paramsstruct.For example following method
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/examples/ondeck/postgresql/city.sql.go#L28
may easily become
Because table contains two columns
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/examples/ondeck/postgresql/schema/0001_city.sql#L1-L4
and the query uses all of them
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/examples/ondeck/postgresql/query/city.sql#L15-L21
Implementation
For output parameters there is struct "deduplication"
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/internal/codegen/golang/result.go#L183
I believe we need to introduce the same deduplication for input parameters
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/internal/codegen/golang/result.go#L166
BetaWas this translation helpful?Give feedback.
All reactions