Commits

Toni Ruža committed c4df259

Added get_all_entities backend method and generalized the method call forwarding from roktar to it's backend.

  • Participants
  • Parent commits a01592a

Comments (0)

Files changed (4)

File roktar/_roktar.py

     def close(self):
         self._backend.close()
         self._configuration.close()
-
-    def create_entity(self, data, author=None, data_for_indexing=None):
-        return self._backend.create_entity(data, author, data_for_indexing)
-    
-    def get_entity(self, entity_id):
-        return self._backend.get_entity(entity_id)
-    
-    def get_changes(self, entity_id):
-        return self._backend.get_changes(entity_id)
+        
+    def __getattr__(self, name):
+        return getattr(self._backend, name)

File roktar/backends/_interface.py

     @abstractmethod
     def get_changes(self, entity_id):
         pass
+    
+    @abstractmethod
+    def get_all_entities(self):
+        pass

File roktar/backends/sqlite_backend.py

         self.cursor = cursor = self.db_connection.cursor()
 
         table_definitions = [
-            row.sql
+            row["sql"]
             for row in cursor.execute("SELECT sql FROM sqlite_master")
         ]
         table_definitions = sorted(filter(None, table_definitions))
 
     def get_changes(self, entity_id):
         return self.select("Changes", entity_id=entity_id)
+    
+    def get_all_entities(self):
+        return (
+            (data["entity_id"], loads(str(data["cached_value"])))
+            for data in self.select("Entities")
+        )

File tests/test_data_handling.py

         self.assertEqual(change["field_name"], "hello")
         self.assertEqual(loads(str(change["old_value"])), None)
         self.assertEqual(loads(str(change["new_value"])), "world")
+        
+        all_entities = list(self.roktar.get_all_entities())
+        self.assertEqual(len(all_entities), 1)
+        e_id, e = all_entities[0]
+        self.assertEqual(e_id, entity_id)
+        self.assertEqual(e, entity)