Skip to content

Parameters instead of structs #2098

Description

@polderudo

What do you want to change?

Right now, when we do an insert/update/select sqlc generates a struct for the needed sql-parameters most time.
If one changes a parsed query (e.g. add a new param), the generated struct also changes. Now we have to check every single location, where the struct is used, in order to be sure, that we populate the struct with all new values, else the go default values will be used for that fields.

It would be a very helpfull feature, if we could have the values just as regular params on the query function. The compiler would warn if we miss a value. Maybe create the struct inline and use it only inside the functions, so we don't have to change the other functionality?

What database engines need to be changed?

No response

What programming language backends need to be changed?

Go

Activity

  1. added
    enhancementNew feature or request
    triageNew issues that hasn't been reviewed
    on Feb 20, 2023
  2. andrewmbenton commented on Feb 22, 2023

    @andrewmbenton
    Collaborator

    Presumably the choice to use structs as function arguments was to avoid creating super-long function signatures, which are unwieldy. Maybe this could be a configuration option that doesn't change default behavior?

  3. polderudo commented on Feb 22, 2023

    @polderudo
    Author

    Sure as an optional configuration. For me I would be ok to have those long param lists, but have the compiler check for missing params. Would save a bunch of tests

  4. removed
    triageNew issues that hasn't been reviewed
    on Feb 22, 2023
  5. kyleconroy commented on Feb 22, 2023

    @kyleconroy
    Collaborator

    @polderudo Could you take a look at #1558? It would solve your problem, but would change all queries in a sqlc project.

  6. polderudo commented on Feb 23, 2023

    @polderudo
    Author

    @polderudo Could you take a look at #1558? It would solve your problem, but would change all queries in a sqlc project.

    Yes, that would definitely solve my issue. I would use 999 for that parameter then :)

  7. mortenson commented on Jun 20, 2023

    @mortenson

    I like params, but since a default "empty" value can be a bit dangerous in a query I started using a CI check to enforces that all params are always explicitly defined using exhaustruct:

    exhaustruct -i '.*db\..*' <your module name>
    

    Where db is the name of my sqlc module that defines param-structs.

  8. andrewmbenton commented on Sep 22, 2023

    @andrewmbenton
    Collaborator

    Closing since we now have the query_parameter_limit option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions