I often end up serialising data table rows to json and I got tired of writing bespoke serialisers. Here’s my first stab at making a generic serialiser which just works off the table name:
https://anvil.works/build#clone:Q5H6HXMVPNV6ROXZ=AWVB433SJ5P55QTPUZ4KKHZT
(At some point, I’ll get around to adding the ability to exclude columns in linked tables).
6 Likes
I couldn’t see a way to extract the linked table names and had to resort to passing a dict of those into the function. If anyone can see a way to avoid the need for that dict, I’d love to hear it!
1 Like
This is great - and you’re right - it’s a shame you have to define the linked tables dictionary beforehand…
the datatable
clearly knows that star_system
column belongs to the star_systems
table… so why should you have to tell it what it already knows!!!
I don’t think there would be a nice way to do do this as yet @shaun ?
It would be nice if when you do app_tables.planets.list_columns()
, instead of:
[{'type': 'string', 'name': 'name'},
{'type': 'liveObject', 'name': 'star_system'}]
you got:
[{'type': 'string', 'name': 'name'},
{'type': 'liveObject', 'name': 'star_system', 'app_table':'star_systems'}]
or something…
2 Likes
shaun
February 3, 2020, 10:24am
5
I don’t think there would be a nice way to do do this as yet @shaun ?
Correct, you can’t currently get the name of a Data Table (or linked Data Table) programmatically.
2 Likes
I’ve updated the function to handle column exclusion properly.
1 Like
Now refactored, generally tidied up and pretty much about as good as I can get it.
2 Likes
Updated for marshmallow v3.x
KR1
April 23, 2023, 12:49pm
9
owen.campbell:
generic serialise
Do you have still the example saved somwhere?