Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/test_tinydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,10 @@ def test_gc(tmpdir):
table.insert({'int': 13})
assert len(table.search(where('int') == 13)) == 1
assert table.all() == [{'something': 'else'}, {'int': 13}]


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())
10 changes: 7 additions & 3 deletions tinydb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class TinyDB(object):
and getting tables.
"""

DEFAULT_TABLE = '_default'
DEFAULT_STORAGE = JSONStorage

def __init__(self, *args, **kwargs):
Expand All @@ -66,20 +67,23 @@ def __init__(self, *args, **kwargs):
with ``args`` and ``kwargs``.
"""

storage = kwargs.pop('storage', TinyDB.DEFAULT_STORAGE)
table = kwargs.pop('default_table', TinyDB.DEFAULT_TABLE)

# Prepare the storage
self._opened = False

storage = kwargs.pop('storage', TinyDB.DEFAULT_STORAGE)
#: :type: Storage
self._storage = storage(*args, **kwargs)

self._opened = True

# Prepare the default table

self._table_cache = {}
self._table = self.table('_default')
self._table = self.table(table)

def table(self, name='_default', **options):
def table(self, name=DEFAULT_TABLE, **options):
"""
Get access to a specific table.

Expand Down