asdine / storm

Simple and powerful toolkit for BoltDB
MIT License
2.06k stars 139 forks source link

Make it clear in the README that calling db.Save, db.Update, etc. by themselves is thread-safe #266

Open novemberisms opened 4 years ago

novemberisms commented 4 years ago

Hi,

As someone looking at storm coming from Bolt, it's not at all written in the README that the methods on DB or Node like Save, Update, One, or All, can be called by themselves outside of a bolt.DB.View, bolt.DB.Update, or bolt.DB.Batch closure.

In vanilla bolt, practically all transactions must be done within one of those methods to ensure thread-safety.

Therefore most users coming from bolt with wrap all their storm.DB methods in a bolt transaction. This might be fine, but they should be made aware from the start that they don't need to because it is threadsafe by default.

The only way I was able to figure this out was to dig into the storm source code and see that indeed, db.Save, db.Update, etc. do internally use bolt.DB.Update and bolt.DB.View even if you don't call them from a transaction. This is not ideal.

Someone already had this question in the past (#199). And I'm sure me and many others did too. To prevent more people asking the same question, I suggest making it clear or having a section in the README that this is the case.