Skip to content

Commit

Permalink
feat: new method for creating filtered adapter with existing gorm ins…
Browse files Browse the repository at this point in the history
…tance (#188)
  • Loading branch information
gurbaj5124871 authored Nov 4, 2022
1 parent 87dd6fe commit 8d7ae4b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ func NewFilteredAdapter(driverName string, dataSourceName string, params ...inte
return adapter, err
}

// NewFilteredAdapterByDB is the constructor for FilteredAdapter.
// Casbin will not automatically call LoadPolicy() for a filtered adapter.
func NewFilteredAdapterByDB(db *gorm.DB, prefix string, tableName string) (*Adapter, error) {
adapter := &Adapter{
tablePrefix: prefix,
tableName: tableName,
isFiltered: true,
}
adapter.db = db.Scopes(adapter.casbinRuleTable()).Session(&gorm.Session{Context: db.Statement.Context})

return adapter, nil
}

// NewAdapterByDB creates gorm-adapter by an existing Gorm instance
func NewAdapterByDB(db *gorm.DB) (*Adapter, error) {
return NewAdapterByDBUseTableName(db, "", defaultTableName)
Expand Down

0 comments on commit 8d7ae4b

Please sign in to comment.