diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-03 18:18:35 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-03 18:18:41 +0100 |
commit | d703e712f7b6f6741010360617d88dfb067b349d (patch) | |
tree | b18aa290843eb95bdcabb59da288e5e73df32879 /synapse | |
parent | Added federation protocol urls section from other docs. (diff) | |
download | synapse-d703e712f7b6f6741010360617d88dfb067b349d.tar.xz |
Add support to _simple_insert() to do INSERT OR REPLACE
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/_base.py | 10 |
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) |