Auto-update: Thu Jul 25 09:38:32 PDT 2024

This commit is contained in:
sanj 2024-07-25 09:38:32 -07:00
parent f802768053
commit d338b5bab3

View file

@ -398,14 +398,20 @@ class APIConfig(BaseModel):
""", last_synced_version, source_pool_entry['ts_id']) """, last_synced_version, source_pool_entry['ts_id'])
for change in changes: for change in changes:
columns = change.keys() # Convert change.keys() to a list
columns = list(change.keys())
values = [change[col] for col in columns] values = [change[col] for col in columns]
await dest_conn.execute(f"""
# Construct the SQL query
insert_query = f"""
INSERT INTO "{table_name}" ({', '.join(columns)}) INSERT INTO "{table_name}" ({', '.join(columns)})
VALUES ({', '.join(f'${i+1}' for i in range(len(columns)))}) VALUES ({', '.join(f'${i+1}' for i in range(len(columns)))})
ON CONFLICT (id) DO UPDATE SET ON CONFLICT (id) DO UPDATE SET
{', '.join(f"{col} = EXCLUDED.{col}" for col in columns if col != 'id')} {', '.join(f"{col} = EXCLUDED.{col}" for col in columns if col != 'id')}
""", *values) """
# Execute the query
await dest_conn.execute(insert_query, *values)
if changes: if changes:
await self.update_sync_status(table_name, source_pool_entry['ts_id'], changes[-1]['version']) await self.update_sync_status(table_name, source_pool_entry['ts_id'], changes[-1]['version'])