Skip to content

Use model struct as method parameter #872

@maratori

Description

@maratori

Some of insert queries contains all columns of table as input parameters.
In that case generated method may apply model struct instead of ...Params struct.

For example following method
https://github.com/kyleconroy/sqlc/blob/bda1a0089e042a33f64f9dd1b59a2c3631fb659e/examples/ondeck/postgresql/city.sql.go#L28
may easily become

func (q *Queries) CreateCity(ctx context.Context, arg City) (City, error) {

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions