casbin / gorm-adapter

GORM adapter for Casbin, see extended version of GORM Adapter Ex at: https://github.com/casbin/gorm-adapter-ex
https://github.com/casbin/casbin
Apache License 2.0
692 stars 207 forks source link

How do I use transaction ? #175

Closed VaneLord67 closed 2 years ago

casbin-bot commented 2 years ago

@tangyang9464 @JalinWang @imp2002

JalinWang commented 2 years ago

@VaneLord67 Could you please provide more details about what you want to achieve (scenario&purpose) ?

VaneLord67 commented 2 years ago

@VaneLord67 Could you please provide more details about what you want to achieve (scenario&purpose) ?

@JalinWang I want to remove and add policies in a transaction just like this:

enforcer.Transaction(func(tx *gorm.DB) error {
    _, err = tx.RemoveFilteredPolicy(....)
    if err != nil {return err}
    _, err = tx.AddPolicy(....)
    if err != nil {return err}
    return nil
}) 
hsluoyz commented 2 years ago

@VaneLord67 @JalinWang does gorm support transactions?

VaneLord67 commented 2 years ago

@VaneLord67 @JalinWang does gorm support transactions?

https://gorm.io/docs/transactions.html

hsluoyz commented 2 years ago

@JalinWang plz work on it

VaneLord67 commented 2 years ago

@JalinWang I have a simple implementation at #176