diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-13 16:27:14 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-13 18:03:41 +0100 |
commit | 336987bb8debec9dcdbe27d59ce3889b39f86dbb (patch) | |
tree | a2009c85c449021dcae897424f4a1b351f01ed2f /synapse/storage/_base.py | |
parent | Convert im schema to a 'one' table structure (diff) | |
download | synapse-336987bb8debec9dcdbe27d59ce3889b39f86dbb.tar.xz |
Initial stab at refactoring the SQL tables, including rejigging some of the storage layer.
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r-- | synapse/storage/_base.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 65f691ead4..03537b7e3b 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - import logging from twisted.internet import defer @@ -20,6 +19,8 @@ from twisted.internet import defer from synapse.api.errors import StoreError import collections +import json + logger = logging.getLogger(__name__) @@ -28,6 +29,7 @@ class SQLBaseStore(object): def __init__(self, hs): self._db_pool = hs.get_db_pool() + self.event_factory = hs.get_event_factory() def cursor_to_dict(self, cursor): """Converts a SQL cursor into an list of dicts. @@ -63,6 +65,9 @@ class SQLBaseStore(object): return decoder(cursor) return self._db_pool.runInteraction(interaction) + def _execut_query(self, query, *args): + return self._execute(self.cursor_to_dict, *args) + # "Simple" SQL API methods that operate on a single table with no JOINs, # no complex WHERE clauses, just a dict of values for columns. @@ -279,6 +284,16 @@ class SQLBaseStore(object): return self._db_pool.runInteraction(func) + def _parse_event_from_row(self, row_dict): + d = copy.deepcopy({k: v for k, v in row.items() if v}) + d.update(json.loads(row["unrecognized_keys"])) + del d["unrecognized_keys"] + + return self.event_factory.create_event( + etype=d["type"], + **d + ) + class Table(object): """ A base class used to store information about a particular table. |