Skip to content

Commit

Permalink
better rows close
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Aug 18, 2023
1 parent 586b3f4 commit c55ea94
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions data/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ func (p *Psql) handleDriver(dbTransactionID int64, driverAddress string) (dbDriv

if rows.Next() {
err = rows.Scan(&dbDriverID)
rows.Close()
return
}
defer rows.Close()
rows.Close()

row := p.tx.QueryRow("INSERT INTO hivemapper.drivers (address, transaction_id) VALUES ($1, $2) RETURNING id", driverAddress, dbTransactionID)
err = row.Err()
Expand All @@ -150,9 +151,11 @@ func (p *Psql) handleFleet(dbTransactionID int64, fleetAddress string) (dbDriver
}
if rows.Next() {
err = rows.Scan(&dbDriverID)
rows.Close()
return
}
defer rows.Close()

rows.Close()

row := p.tx.QueryRow("INSERT INTO hivemapper.fleets (address, transaction_id) VALUES ($1, $2) RETURNING id", fleetAddress, dbTransactionID)
err = row.Err()
Expand All @@ -172,9 +175,10 @@ func (p *Psql) handleFleetDriver(dbTransactionID int64, dbFleetID int64, dbDrive

if rows.Next() {
err = rows.Scan(&dbDriverID)
rows.Close()
return
}
defer rows.Close()
rows.Close()

row := p.tx.QueryRow("INSERT INTO hivemapper.fleet_drivers (transaction_id, fleet_id, driver_id) VALUES ($1, $2, $3) RETURNING id", dbTransactionID, dbFleetID, dbDriverID)
err = row.Err()
Expand Down

0 comments on commit c55ea94

Please sign in to comment.