Skip to content

Commit

Permalink
Add on_duplicate_key_update for mysql
Browse files Browse the repository at this point in the history
testCollections still fails.
  • Loading branch information
timj committed Jul 16, 2020
1 parent 4740c59 commit 5406471
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/lsst/daf/butler/registry/databases/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ def expandDatabaseEntityName(self, shrunk: str) -> str:
return self._shrinker.expand(shrunk)

def replace(self, table: sqlalchemy.schema.Table, *rows: dict) -> None:
# This is all wrong
if not self.isWriteable():
raise ReadOnlyDatabaseError(f"Attempt to replace into read-only database '{self}'.")
if not rows:
return
raise NotImplementedError("No support for replace in MySQL")
# This uses special support for UPSERT in MySQL backend:
# https://docs.sqlalchemy.org/en/13/dialects/mysql.html#insert-on-duplicate-key-update-upsert
query = sqlalchemy.dialects.mysql.dml.insert(table)
data = {column.name: getattr(query.inserted, column.name)
for column in table.columns
if hasattr(query.inserted, column.name)}
query = query.on_duplicate_key_update(**data)
self._connection.execute(query, *rows)

0 comments on commit 5406471

Please sign in to comment.