Get the names of all tables in the database. :returns: a set of table names
(self)
| 133 | return table |
| 134 | |
| 135 | def tables(self) -> Set[str]: |
| 136 | """ |
| 137 | Get the names of all tables in the database. |
| 138 | |
| 139 | :returns: a set of table names |
| 140 | """ |
| 141 | |
| 142 | # TinyDB stores data as a dict of tables like this: |
| 143 | # |
| 144 | # { |
| 145 | # '_default': { |
| 146 | # 0: {document...}, |
| 147 | # 1: {document...}, |
| 148 | # }, |
| 149 | # 'table1': { |
| 150 | # ... |
| 151 | # } |
| 152 | # } |
| 153 | # |
| 154 | # To get a set of table names, we thus construct a set of this main |
| 155 | # dict which returns a set of the dict keys which are the table names. |
| 156 | # |
| 157 | # Storage.read() may return ``None`` if the database file is empty, |
| 158 | # so we need to consider this case to and return an empty set in this |
| 159 | # case. |
| 160 | |
| 161 | return set(self.storage.read() or {}) |
| 162 | |
| 163 | def drop_tables(self) -> None: |
| 164 | """ |