I am looking for the only SQLAlchemy solution to convert a dict obtained from a form view into a series of rows in a database, one for each field presented. This applies to settings and settings that vary widely across applications. But this is most likely applicable for creating a pivot table, such as functionality. I saw such things in ETL tools, but I was looking for a way to do this directly in ORM. I could not find the documentation, but maybe I missed something.
Example:
Submitted from the form: {"UniqueId": 1, "a": 23, "b": "Hello", "c": "World"}
I would like it to be converted (in ORM) so that it is written to the database as follows:
_______________________________________ |UniqueId| ItemName | ItemValue | --------------------------------------- | 1 | a | 23 | --------------------------------------- | 1 | b | Hello | --------------------------------------- | 1 | c | World | ---------------------------------------
After selection, the result will be converted (in ORM) back to the data string from each of the individual values.
--------------------------------------------------- | UniqueId | a | b | c | --------------------------------------------------- | 1 | 23 | Hello | World | ---------------------------------------------------
I would suggest that when upgrading, it would be best to wrap the delete / create in the transaction so that the current records are deleted and new ones are inserted.
The final list of ItemNames will be saved in a separate table.
Fully open to more elegant solutions, but, if at all possible, will avoid using a database.
I am using the declarative_base method with SQLAlchemy.
Thanks in advance...
Greetings
Floor