summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-09-03 18:21:55 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-09-03 18:21:55 +0100
commit01e83c96803e1798d487f30760d01db08dd34ccf (patch)
treeae347aa851e93355433792daa2d62f33af9bc850 /synapse/storage/_base.py
parentMerge branch 'develop' into paul/schema_breaking_changes (diff)
parentAdd support to _simple_insert() to do INSERT OR REPLACE (diff)
downloadsynapse-github/paul/schema_breaking_changes.tar.xz
Merge branch 'develop' into paul/schema_breaking_changes github/paul/schema_breaking_changes paul/schema_breaking_changes
Diffstat (limited to 'synapse/storage/_base.py')
-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)