We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.28.0
I have the following query
-- name: Obtener_maximo :one SELECT max(columna) from tabla;
[ columna in integer primary key in sqlite]
The generated code is like this
func (q *Queries) Obtener_maximo(ctx context.Context) (interface{}, error) { row := q.db.QueryRowContext(ctx, obtener_maximo) var max interface{} err := row.Scan(&max) return max, err }
The problem with this code is that it returns a interface{} that can be of any type, which is useless. Instead, it should return an sql.NullInt64
It is enough to change the declaration of the max variable as
var max sql.NullInt64
A solution would be add an optional type to the query anotation like
-- name: Obtener_maximo :one sql.NullInt64 SELECT max(columna) from tabla;
to be used in the generated code.
The text was updated successfully, but these errors were encountered:
It turns out that you can use the result of the query via a type assertion like
value,_ := Obtener_maximo().(int64)
I didn't realize that. May be it should be better explained in the documentation.
Sorry, something went wrong.
No branches or pull requests
Version
1.28.0
What happened?
I have the following query
-- name: Obtener_maximo :one
SELECT max(columna) from tabla;
[ columna in integer primary key in sqlite]
The generated code is like this
func (q *Queries) Obtener_maximo(ctx context.Context) (interface{}, error) {
row := q.db.QueryRowContext(ctx, obtener_maximo)
var max interface{}
err := row.Scan(&max)
return max, err
}
The problem with this code is that it returns a interface{} that can be of any type, which is useless. Instead, it should return an sql.NullInt64
It is enough to change the declaration of the max variable as
var max sql.NullInt64
A solution would be add an optional type to the query anotation like
-- name: Obtener_maximo :one sql.NullInt64
SELECT max(columna) from tabla;
to be used in the generated code.
The text was updated successfully, but these errors were encountered: