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? |
3 replies
|
Seems like a flag in -- name: PersistNewCity :entity :one
INSERT INTO city ( * ) VALUES ( ** )
RETURNING *;results in func (q *Queries) PersistNewCity(ctx context.Context, arg City) (City, error) {where expands |
0 replies
|
+1 How do maintainers feel about it? We can probably help open a PR |
0 replies
|
We really need it |
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.
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
All reactions