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
678 stars 206 forks source link

[feature] create if not exist for Update APIs #194

Closed nonchan7720 closed 1 year ago

nonchan7720 commented 1 year ago

Want to prioritize this issue? Try:

issuehunt-to-marktext


What's your scenario? What do you want to achieve? Do you plan to offer a feature like Upsert?

UpdateXXX and UpdateFilteredXXX assume that existing policies and rules exist. We are willing to create the features we are requesting if they do not exist and update them if they do. I would also like to see this same feature in Grouping.

The reason I need this is that I am trying to use RDB for storing policies, and I want to achieve this within the same transaction. Adapter to be used

casbin-bot commented 1 year ago

@tangyang9464 @JalinWang

casbin-bot commented 1 year ago

@tangyang9464 @JalinWang @imp2002

nonchan7720 commented 1 year ago

Sorry. I made a mistake in the content.

What I meant to say is that I would like to see a feature like Replace.

As an example of use, we would like to filter Policy and Grouping to perform a search, delete existing rules if they exist, and create new rules as given.

hsluoyz commented 1 year ago

@nonchan7720 what you said is how Update APIs work now? If exist, then update. If not exist, then error (and not update). Isn't this what you want?

nonchan7720 commented 1 year ago

@hsluoyz My hope is that existing rules will be created and propagated to watchers and others even if they do not exist.

Expect line 445 to be skipped. https://github.com/casbin/casbin/blob/540b521da0f969ed8f1b348c6fb34edc0e668a86/internal_api.go#L443-L447

hsluoyz commented 1 year ago

@nonchan7720 this requirement is very rare. You can fork the code and use your own fork