asdine / storm

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

Is there a way to get the next sequence before saving an object? #286

Open mivinci opened 3 years ago

mivinci commented 3 years ago

I have a struct as follows

type struct App {
    ID   int `storm:"increment"`
    Uid  int `storm:"index"`
    Key string
}

and I want to give a value to Key before saving each instance, the value is calculated with ID and Uid. So is there a way to get the next sequence before saving an object like the way you use BoltDB?

Yes, I can make this done by updating the key after saving the object, but that's several more lines of code and I'm afraid of two IO operations for every single creation of an object.