def save(self, db_conn: DatabaseConnection) -> None:
"""Save as self.history entries, but first wipe old ones."""
- db_conn.exec(f'DELETE FROM {self.table_name} WHERE parent = ?',
- (self.parent.id_,))
- for timestamp, value in self.history.items():
- db_conn.exec(f'INSERT INTO {self.table_name} VALUES (?, ?, ?)',
- (self.parent.id_, timestamp, value))
+ db_conn.rewrite_relations(self.table_name, 'parent', self.parent.id_,
+ [[item[0], item[1]]
+ for item in self.history.items()])