Return the ID for a newly inserted document.
(self)
| 661 | yield self.document_class(doc, self.document_id_class(doc_id)) |
| 662 | |
| 663 | def _get_next_id(self): |
| 664 | """ |
| 665 | Return the ID for a newly inserted document. |
| 666 | """ |
| 667 | |
| 668 | # If we already know the next ID |
| 669 | if self._next_id is not None: |
| 670 | next_id = self._next_id |
| 671 | self._next_id = next_id + 1 |
| 672 | |
| 673 | return next_id |
| 674 | |
| 675 | # Determine the next document ID by finding out the max ID value |
| 676 | # of the current table documents |
| 677 | |
| 678 | # Read the table documents |
| 679 | table = self._read_table() |
| 680 | |
| 681 | # If the table is empty, set the initial ID |
| 682 | if not table: |
| 683 | next_id = 1 |
| 684 | self._next_id = next_id + 1 |
| 685 | |
| 686 | return next_id |
| 687 | |
| 688 | # Determine the next ID based on the maximum ID that's currently in use |
| 689 | max_id = max(self.document_id_class(i) for i in table.keys()) |
| 690 | next_id = max_id + 1 |
| 691 | |
| 692 | # The next ID we will return AFTER this call needs to be larger than |
| 693 | # the current next ID we calculated |
| 694 | self._next_id = next_id + 1 |
| 695 | |
| 696 | return next_id |
| 697 | |
| 698 | def _read_table(self) -> Dict[str, Mapping]: |
| 699 | """ |