Drop a specific table from the database. **CANNOT BE REVERSED!** :param name: The name of the table to drop.
(self, name: str)
| 174 | self._tables.clear() |
| 175 | |
| 176 | def drop_table(self, name: str) -> None: |
| 177 | """ |
| 178 | Drop a specific table from the database. **CANNOT BE REVERSED!** |
| 179 | |
| 180 | :param name: The name of the table to drop. |
| 181 | """ |
| 182 | |
| 183 | # If the table is currently opened, we need to forget the table class |
| 184 | # instance |
| 185 | if name in self._tables: |
| 186 | del self._tables[name] |
| 187 | |
| 188 | data = self.storage.read() |
| 189 | |
| 190 | # The database is uninitialized, there's nothing to do |
| 191 | if data is None: |
| 192 | return |
| 193 | |
| 194 | # The table does not exist, there's nothing to do |
| 195 | if name not in data: |
| 196 | return |
| 197 | |
| 198 | # Remove the table from the data dict |
| 199 | del data[name] |
| 200 | |
| 201 | # Store the updated data back to the storage |
| 202 | self.storage.write(data) |
| 203 | |
| 204 | @property |
| 205 | def storage(self) -> Storage: |