I would like to modify an activity's exchanges and save the activity back to the database.
It is possible to change other aspects of the activity, like its name:
some_act['name'] = "some new name"
and then save the activity with:
some_act.save()
It is also possible to modify exchanges the same way:
some_exc['scale"] = 0.5
and then save the exchange with:
some_exc.save()
However, the only way I have found to add/delete exchanges from a specific activity is to go through the dictionary version
of the activity:
some_act_dataset = some_act._data
some_act_dataset['exchanges'] = [{exchange1}, {exchange2}] # exc must be valid exchange dict
The problem is that I don't know how to save the new activity (as dict) back to the database.
some_act_dataset.save()
doesn't work, since dictionaries don't have a save
method.
Database("my_database").write(some_act_dataset)
overwrites all the other data in the database.
I could work in the loaded database:
loaded_db = Database("my_database").load()
and make the changes I need in the resulting dictionary, and then write the whole database, but when the databases are big, this seems like a costly operation.
So, the question is: is there a way to modify an activity's exchanges and save the activity back to the database without needing to overwrite the entire database?