Skip to content

Commit

Permalink
set finalizer for adapter (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Mar 31, 2024
1 parent 4a3edd8 commit c1a9355
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"runtime"

"github.com/casbin/casbin/v2/model"
"github.com/casbin/casbin/v2/persist"
Expand Down Expand Up @@ -59,6 +60,12 @@ func NewAdapter(driverName, dataSourceName string, opts ...adapterOption) (*bunA
return nil, err
}

runtime.SetFinalizer(b, func(a *bunAdapter) {
if err := a.db.Close(); err != nil {
panic(err)
}
})

return b, nil
}

Expand Down

0 comments on commit c1a9355

Please sign in to comment.