Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ type Adapter struct {
muInitialize sync.Once
}

var (
_ persist.Adapter = (*Adapter)(nil)
_ persist.BatchAdapter = (*Adapter)(nil)
)

// finalizer is the destructor for Adapter.
func finalizer(a *Adapter) {
sqlDB, err := a.db.DB()
Expand Down Expand Up @@ -709,6 +714,16 @@ func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error
return a.db.Clauses(clause.OnConflict{DoNothing: true}).Create(&lines).Error
}

// AddPoliciesCtx adds multiple policy rules to the storage.
func (a *Adapter) AddPoliciesCtx(ctx context.Context, sec string, ptype string, rules [][]string) error {
var lines []CasbinRule
for _, rule := range rules {
line := a.savePolicyLine(ptype, rule)
lines = append(lines, line)
}
return a.db.WithContext(ctx).Clauses(clause.OnConflict{DoNothing: true}).Create(&lines).Error
}
Comment thread
hsluoyz marked this conversation as resolved.

// Transaction perform a set of operations within a transaction.
func (a *Adapter) Transaction(e casbin.IEnforcer, fc func(casbin.IEnforcer) error, opts ...*sql.TxOptions) error {
// ensure the transactionMu is initialized
Expand Down
Loading