Skip to content

Commit

Permalink
Document DEFAULT_STORAGE and DEFAULT_TABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
msiemens committed Apr 23, 2016
1 parent 27862f5 commit 9e3eab6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
28 changes: 21 additions & 7 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,27 @@ To remove all tables from a database, use:

>>> db.purge_tables()

.. note::

TinyDB uses a table named ``_default`` as default table. All operations
on the database object (like ``db.insert(...)``) operate on this table.

.. _query_caching:

You can get a list with the names of all tables in your database:

>>> db.tables()
{'_default', 'table_name'}

Default Table
.............

TinyDB uses a table named ``_default`` as the default table. All operations
on the database object (like ``db.insert(...)``) operate on this table.
The name of this table can be modified by either passing ``default_table``
to the ``TinyDB`` constructor or by setting the ``DEFAULT_TABLE`` class
variable to modify the default table name for all instances:

>>> #1: for a single instance only
>>> TinyDB(storage=SomeStorage, default_table='my-default')
>>> #2: for all instances
>>> TinyDB.DEFAULT_TABLE = 'my-default'

.. _query_caching:

Query Caching
.............

Expand Down Expand Up @@ -389,6 +398,11 @@ To use the in-memory storage, use:
`json.dump(...) <https://docs.python.org/2/library/json.html#json.dump>`_
method.

To modify the default storage for all ``TinyDB`` instances, set the
``DEFAULT_STORAGE`` class variable:

>>> TinyDB.DEFAULT_STORAGE = MemoryStorage

Middlewares
...........

Expand Down
6 changes: 6 additions & 0 deletions tests/test_tinydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,5 +414,11 @@ def test_gc(tmpdir):
def test_non_default_table():
db = TinyDB(storage=MemoryStorage)
assert [TinyDB.DEFAULT_TABLE] == list(db.tables())

db = TinyDB(storage=MemoryStorage, default_table='non-default')
assert ['non-default'] == list(db.tables())

db.purge_tables()
TinyDB.DEFAULT_TABLE = 'non-default'
db = TinyDB(storage=MemoryStorage)
assert ['non-default'] == list(db.tables())

0 comments on commit 9e3eab6

Please sign in to comment.