jschaf / pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
MIT License
281 stars 26 forks source link

Fix result type decl for nullable :one queries #77

Closed jschaf closed 1 year ago

jschaf commented 1 year ago

Previously, if a query returned a single nullable column, pggen would return the correct type *string, but only because we took the address of the input.

Bad code:

var item string
if err := row.Scan(&item); err != nil {
    return &item, fmt.Errorf("query StringAggFirstName: %w", err)
}
return &item, nil

Fixed code:

var item *string
if err := row.Scan(&item); err != nil {
    return item, fmt.Errorf("query StringAggFirstName: %w", err)
}
return item, nil

Fixes #75.