summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-09-03 18:18:35 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-09-03 18:18:41 +0100
commitd703e712f7b6f6741010360617d88dfb067b349d (patch)
treeb18aa290843eb95bdcabb59da288e5e73df32879 /synapse
parentAdded federation protocol urls section from other docs. (diff)
downloadsynapse-d703e712f7b6f6741010360617d88dfb067b349d.tar.xz
Add support to _simple_insert() to do INSERT OR REPLACE
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/_base.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index aaa09f47d0..bae50e7d1f 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -79,19 +79,21 @@ class SQLBaseStore(object):
     # "Simple" SQL API methods that operate on a single table with no JOINs,
     # no complex WHERE clauses, just a dict of values for columns.
 
-    def _simple_insert(self, table, values):
+    def _simple_insert(self, table, values, or_replace=False):
         """Executes an INSERT query on the named table.
 
         Args:
             table : string giving the table name
             values : dict of new column names and values for them
+            or_replace : bool; if True performs an INSERT OR REPLACE
         """
         return self._db_pool.runInteraction(
-            self._simple_insert_txn, table, values,
+            self._simple_insert_txn, table, values, or_replace=or_replace
         )
 
-    def _simple_insert_txn(self, txn, table, values):
-        sql = "INSERT INTO %s (%s) VALUES(%s)" % (
+    def _simple_insert_txn(self, txn, table, values, or_replace=False):
+        sql = "%s INTO %s (%s) VALUES(%s)" % (
+            ("INSERT OR REPLACE" if or_replace else "INSERT"),
             table,
             ", ".join(k for k in values),
             ", ".join("?" for k in values)