Generate and Increment the counter
(self)
| 2116 | super().__init__(*args, **kwargs) |
| 2117 | |
| 2118 | def generate(self): |
| 2119 | """ |
| 2120 | Generate and Increment the counter |
| 2121 | """ |
| 2122 | sequence_name = self.get_sequence_name() |
| 2123 | sequence_id = f"{sequence_name}.{self.name}" |
| 2124 | collection = get_db(alias=self.db_alias)[self.collection_name] |
| 2125 | |
| 2126 | counter = collection.find_one_and_update( |
| 2127 | filter={"_id": sequence_id}, |
| 2128 | update={"$inc": {"next": 1}}, |
| 2129 | return_document=ReturnDocument.AFTER, |
| 2130 | upsert=True, |
| 2131 | ) |
| 2132 | return self.value_decorator(counter["next"]) |
| 2133 | |
| 2134 | def set_next_value(self, value): |
| 2135 | """Helper method to set the next sequence value""" |