def topic_data_update_one(self, id_: int, one: any, topic_name: str): table_name = 'topic_' + topic_name table = self.get_topic_table_by_name(table_name) stmt = self.build_stmt("update", table_name, table) stmt = stmt.where(eq(table.c['id_'], id_)) one_dict = convert_to_dict(one) values = self.build_mysql_updates_expression( table, capital_to_lower(one_dict), "update") stmt = stmt.values(values) with self.engine.begin() as conn: conn.execute(stmt)
def topic_data_update_one_with_version(self, id_: int, version_: int, one: any, topic_name: str): table_name = 'topic_' + topic_name table = self.get_topic_table_by_name(table_name) stmt = self.build_stmt("update", table_name, table) stmt = stmt.where( and_(eq(table.c['id_'], id_), eq(table.c['version_'], version_))) one_dict = convert_to_dict(one) one_dict['version_'] = version_ values = self.build_mysql_updates_expression( table, capital_to_lower(one_dict), "update") stmt = stmt.values(values) with self.engine.begin() as conn: result = conn.execute(stmt) if result.rowcount == 0: raise OptimisticLockError("Optimistic lock error")