@@ -45,10 +45,11 @@ func (pr *patRepo) Save(ctx context.Context, pat auth.PAT) error {
4545 return errors .Wrap (repoerr .ErrCreateEntity , err )
4646 }
4747
48- _ , err = pr .db .NamedQueryContext (ctx , q , dbPat )
48+ rows , err : = pr .db .NamedQueryContext (ctx , q , dbPat )
4949 if err != nil {
5050 return postgres .HandleError (repoerr .ErrCreateEntity , err )
5151 }
52+ defer rows .Close ()
5253
5354 return nil
5455}
@@ -306,10 +307,11 @@ func (pr *patRepo) Revoke(ctx context.Context, userID, patID string) error {
306307 },
307308 }
308309
309- _ , err := pr .db .NamedQueryContext (ctx , q , upm )
310+ rows , err := pr .db .NamedQueryContext (ctx , q , upm )
310311 if err != nil {
311312 return errors .Wrap (repoerr .ErrUpdateEntity , err )
312313 }
314+ defer rows .Close ()
313315
314316 return nil
315317}
@@ -325,10 +327,11 @@ func (pr *patRepo) Reactivate(ctx context.Context, userID, patID string) error {
325327 ID : patID ,
326328 }
327329
328- _ , err := pr .db .NamedQueryContext (ctx , q , upm )
330+ rows , err := pr .db .NamedQueryContext (ctx , q , upm )
329331 if err != nil {
330332 return errors .Wrap (repoerr .ErrUpdateEntity , err )
331333 }
334+ defer rows .Close ()
332335
333336 return nil
334337}
@@ -340,10 +343,11 @@ func (pr *patRepo) Remove(ctx context.Context, userID, patID string) error {
340343 ID : patID ,
341344 }
342345
343- _ , err := pr .db .NamedQueryContext (ctx , q , upm )
346+ rows , err := pr .db .NamedQueryContext (ctx , q , upm )
344347 if err != nil {
345348 return postgres .HandleError (repoerr .ErrRemoveEntity , err )
346349 }
350+ defer rows .Close ()
347351
348352 return nil
349353}
@@ -355,10 +359,11 @@ func (pr *patRepo) RemoveAllPAT(ctx context.Context, userID string) error {
355359 User : userID ,
356360 }
357361
358- _ , err := pr .db .NamedQueryContext (ctx , q , pm )
362+ rows , err := pr .db .NamedQueryContext (ctx , q , pm )
359363 if err != nil {
360364 return postgres .HandleError (repoerr .ErrRemoveEntity , err )
361365 }
366+ defer rows .Close ()
362367
363368 if err := pr .cache .RemoveUserAllScope (ctx , userID ); err != nil {
364369 return errors .Wrap (repoerr .ErrRemoveEntity , err )
@@ -385,10 +390,11 @@ func (pr *patRepo) AddScope(ctx context.Context, userID string, scopes []auth.Sc
385390 }
386391
387392 if len (newScopes ) > 0 {
388- _ , err := pr .db .NamedQueryContext (ctx , q , toDBScope (newScopes ))
393+ rows , err := pr .db .NamedQueryContext (ctx , q , toDBScope (newScopes ))
389394 if err != nil {
390395 return postgres .HandleError (repoerr .ErrUpdateEntity , err )
391396 }
397+ defer rows .Close ()
392398 }
393399
394400 if err := pr .cache .Save (ctx , userID , scopes ); err != nil {
@@ -473,10 +479,12 @@ func (pr *patRepo) processScope(ctx context.Context, sc auth.Scope) (auth.Scope,
473479 AND optional_domain_id = :optional_domain_id
474480 AND operation = :operation`
475481
476- _ , err = pr .db .NamedQueryContext (ctx , updateWithWildcardQuery , params )
482+ rows , err = pr .db .NamedQueryContext (ctx , updateWithWildcardQuery , params )
477483 if err != nil {
478484 return auth.Scope {}, postgres .HandleError (repoerr .ErrUpdateEntity , err )
479485 }
486+ defer rows .Close ()
487+
480488 return auth.Scope {}, nil
481489 }
482490 }
@@ -575,10 +583,11 @@ func (pr *patRepo) RemoveAllScope(ctx context.Context, patID string) error {
575583
576584 q := `DELETE FROM pat_scopes WHERE pat_id = :pat_id`
577585
578- _ , err := pr .db .NamedQueryContext (ctx , q , pm )
586+ rows , err := pr .db .NamedQueryContext (ctx , q , pm )
579587 if err != nil {
580588 return postgres .HandleError (repoerr .ErrRemoveEntity , err )
581589 }
590+ defer rows .Close ()
582591
583592 if err := pr .cache .RemoveAllScope (ctx , pm .User , patID ); err != nil {
584593 return errors .Wrap (repoerr .ErrRemoveEntity , err )
0 commit comments