MCPcopy
hub / github.com/msiemens/tinydb / TinyDB

Class TinyDB

tinydb/database.py:16–274  ·  view source on GitHub ↗

The main class of TinyDB. The ``TinyDB`` class is responsible for creating the storage class instance that will store this database's documents, managing the database tables as well as providing access to the default table. For table management, a simple ``dict`` is used that

Source from the content-addressed store, hash-verified

14
15
16class TinyDB(TableBase):
17 """
18 The main class of TinyDB.
19
20 The ``TinyDB`` class is responsible for creating the storage class instance
21 that will store this database's documents, managing the database
22 tables as well as providing access to the default table.
23
24 For table management, a simple ``dict`` is used that stores the table class
25 instances accessible using their table name.
26
27 Default table access is provided by forwarding all unknown method calls
28 and property access operations to the default table by implementing
29 ``__getattr__``.
30
31 When creating a new instance, all arguments and keyword arguments (except
32 for ``storage``) will be passed to the storage class that is provided. If
33 no storage class is specified, :class:`~tinydb.storages.JSONStorage` will be
34 used.
35
36 .. admonition:: Customization
37
38 For customization, the following class variables can be set:
39
40 - ``table_class`` defines the class that is used to create tables,
41 - ``default_table_name`` defines the name of the default table, and
42 - ``default_storage_class`` will define the class that will be used to
43 create storage instances if no other storage is passed.
44
45 .. versionadded:: 4.0
46
47 .. admonition:: Data Storage Model
48
49 Data is stored using a storage class that provides persistence for a
50 ``dict`` instance. This ``dict`` contains all tables and their data.
51 The data is modelled like this::
52
53 {
54 'table1': {
55 0: {document...},
56 1: {document...},
57 },
58 'table2': {
59 ...
60 }
61 }
62
63 Each entry in this ``dict`` uses the table name as its key and a
64 ``dict`` of documents as its value. The document ``dict`` contains
65 document IDs as keys and the documents themselves as values.
66
67 :param storage: The class of the storage to use. Will be initialized
68 with ``args`` and ``kwargs``.
69 """
70
71 #: The class that will be used to create table instances
72 #:
73 #: .. versionadded:: 4.0

Callers 15

test_json_kwargsFunction · 0.90
test_json_readwriteFunction · 0.90
test_json_readFunction · 0.90
test_in_memory_closeFunction · 0.90
test_read_onceFunction · 0.90
test_yamlFunction · 0.90
test_caching_readFunction · 0.90
test_caching_json_writeFunction · 0.90
dbFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_json_kwargsFunction · 0.72
test_json_readwriteFunction · 0.72
test_json_readFunction · 0.72
test_in_memory_closeFunction · 0.72
test_read_onceFunction · 0.72
test_yamlFunction · 0.72
test_caching_readFunction · 0.72
test_caching_json_writeFunction · 0.72
dbFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…