summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-07 12:06:01 +0100
committerErik Johnston <erik@matrix.org>2015-04-07 12:06:22 +0100
commitc8d3f6486da29b1e0e36b447948b8971bdf05fd3 (patch)
tree52d37bb4929771b412029b4c17903f5a1512faed /synapse/storage/_base.py
parentDon't use AUTOINCREMENT, use an in memory version (diff)
downloadsynapse-c8d3f6486da29b1e0e36b447948b8971bdf05fd3.tar.xz
Implement or_ignore flag on inserts
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 9f63f07080..a0c1718c27 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -393,7 +393,8 @@ 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, desc="_simple_insert"):
+    def _simple_insert(self, table, values, or_ignore=False,
+                       desc="_simple_insert"):
         """Executes an INSERT query on the named table.
 
         Args:
@@ -403,10 +404,11 @@ class SQLBaseStore(object):
         return self.runInteraction(
             desc,
             self._simple_insert_txn, table, values,
+            or_ignore=or_ignore
         )
 
     @log_function
-    def _simple_insert_txn(self, txn, table, values):
+    def _simple_insert_txn(self, txn, table, values, or_ignore=False):
         sql = "INSERT INTO %s (%s) VALUES(%s)" % (
             table,
             ", ".join(k for k in values),
@@ -418,8 +420,11 @@ class SQLBaseStore(object):
             sql, values.values(),
         )
 
-        txn.execute(sql, values.values())
-        return txn.lastrowid
+        try:
+            txn.execute(sql, values.values())
+        except self.database_engine.module.IntegrityError:
+            if not or_ignore:
+                raise
 
     def _simple_upsert(self, table, keyvalues, values, desc="_simple_upsert"):
         """