Jean-Tiare Le Bigot avatar Jean-Tiare Le Bigot committed cd635ee

add an (untested) table schema persisted layer

Comments (0)

Files changed (2)


 from .table import Table
 from .item import ItemSize
+from .storage import Store
 from collections import defaultdict
 from ddbmock import config
 from ddbmock.utils import push_write_throughput, push_read_throughput
 class DynamoDB(object):
     _shared_data = {
-        'data': {}
+        'data': {},
+        'store': None,
     def __init__(self):
         cls = type(self)
         self.__dict__ = cls._shared_data
+        # At first instanciation, attempt to reload the database schema
+        if is None:
+   = Store('~*schema*~')
+            for table in
+      [] = table
     def hard_reset(self):
         for table in
    # FIXME: should be moved in table
     def list_tables(self):
             raise LimitExceededException("Table limit reached. You can have more than {} tables simultaneously".format(config.MAX_TABLES))
 [name] = Table.from_dict(data)
+[name, None] =[name]
     def _internal_delete_table(self, name):
         if name in
   [name].store.truncate()  # FIXME: should be moved in table
+            del[name, None]
     def delete_table(self, name):
         if name not in


             ret[u'KeySchema'][u'RangeKeyElement'] = self.range_key.to_dict()
         return ret
+    # these 2 functions helps to persist table schema (If store supports it)
+    # please note that only the schema is persisted, not the state
+    def __getstate__(self):
+        return (
+  ,
+            self.rt,
+            self.wt,
+            self.hash_key,
+            self.range_key,
+            'ACTIVE',
+        )
+    def __setstate__(self, state):
+        self.__init__(*state)  # quick and dirty (tm), but it does the job
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.