Skip to content

Commit

Permalink
MySQL - Changed update query instead of merge strategy … (#89)
Browse files Browse the repository at this point in the history
Co-authored-by: Meir Shpilraien (Spielrein) <meir@redislabs.com>
  • Loading branch information
spicy-sauce and MeirShpilraien authored Nov 22, 2021
1 parent ade71d4 commit ddcc906
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions rgsync/Connectors/sql_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ def __init__(self, connection, tableName, pk, exactlyOnceTableName=None):

def PrepereQueries(self, mappings):
def GetUpdateQuery(tableName, mappings, pk):
query = 'REPLACE INTO %s' % tableName
query = 'INSERT INTO %s' % tableName
values = [val for kk, val in mappings.items() if not kk.startswith('_')]
values = [self.pk] + values
values = [pk] + values
values.sort()
query = '%s(%s) values(%s)' % (query, ','.join(values), ','.join([':%s' % a for a in values]))
query = '%s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s' % (query, ','.join(values), ','.join([':%s' % a for a in values]), ','.join(['%s=values(%s)' % (a,a) for a in values]))

return query
self.addQuery = GetUpdateQuery(self.tableName, mappings, self.pk)
self.delQuery = 'delete from %s where %s=:%s' % (self.tableName, self.pk, self.pk)
Expand Down Expand Up @@ -239,9 +240,9 @@ def GetUpdateQuery(tableName, mappings, pk):
VALUES ({})
ON CONFLICT({}) DO UPDATE
SET
{}""".format(tableName, cols, self.pk,
{}""".format(tableName, cols, pk,
value_stmt,
self.pk,
pk,
', '.join(update_stmts))
return query
self.addQuery = GetUpdateQuery(self.tableName, mappings, self.pk)
Expand Down

0 comments on commit ddcc906

Please sign in to comment.