spine-tools / Spine-Database-API

Database interface to Spine generic data model
https://www.tools-for-energy-system-modelling.org/
GNU Lesser General Public License v3.0
6 stars 5 forks source link

Introduce add_update methods into DatabaseMapping #305

Closed manuelma closed 7 months ago

manuelma commented 8 months ago

So the idea is to provide methods that receive an item spec and then add that item if it doesn't exist, or update the current if it exists.

Then, import_data needs to be refactored using these methods - should be very easy and actually the initial definition of the add_update method can be copied directly from the current import_data.

Also, we need to clarify in the documentation of the import_functions module that it is an alternative to add_update that is a bit more compact and convenient in some cases.

I am not sure if we want to start deprecating import_data after this, seems a bit inbuilt into things like the JSON format that is also used for SpineOpt templates. Maybe we can consider updating that JSON format and the templates to work with add_update instead? Anyways I think this last point is for further discussion.

soininen commented 8 months ago

I am not sure if we want to start deprecating import_data after this,

True, you have some good points there. I think we are not in a hurry to deprecate import_functions in any case. Maybe the JSON import could be its own function if we do not have one yet (I have not seen one in spinedb_api but I may have just missed something).

manuelma commented 7 months ago

Done.