sqlclosecheck
sqlclosecheck copied to clipboard
About the scope of the pgx linter
Pgx apparently closes rows when all rows are read and I guess because of this defer seems not needed. But this shouldn't be the case since function might stop before iterating all the rows. Is this a bug or feature?
// Next prepares the next row for reading. It returns true if there is another
// row and false if no more rows are available. It automatically closes rows
// when all rows are read.
Next() bool
Code below does not give any errs
var pgxPool *pgxpool.Pool
func missingClosePgxPool() {
rows, err := pgxPool.Query(context.Background(), "SELECT username FROM users") // want "Rows/Stmt/NamedStmt was not closed"
if err != nil {
log.Fatal(err)
}
for rows.Next() {
}
}