Skip to content

Commit

Permalink
UPSERT when creating timers
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Apr 27, 2020
1 parent 8b404a5 commit 7d9c9e7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fcp_timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ def _db_save_timer(self, timestamp: datetime, proposal_num: int):
with self.store.conn:
self.store.cur.execute("""
INSERT INTO fcp_timers (proposal_num, end_timestamp)
VALUES (%s, %s)
""", (proposal_num, timestamp.timestamp()))
VALUES (%s, %s)
ON CONFLICT (proposal_num)
DO UPDATE
SET end_timestamp = %s
WHERE fcp_timers.proposal_num = %s
""", (
proposal_num, timestamp.timestamp(),
proposal_num, timestamp.timestamp(),
))

def _db_delete_timer(self, proposal_num: int):
"""Deletes a timer from the database"""
Expand Down

0 comments on commit 7d9c9e7

Please sign in to comment.