Currently, I call an external database with some variation of this code. It works, but it requires that I convert the list of tuples into a list of dictionaries.
Then I would get an object. I don’t fully understand it because it appears to be a list of lists. However I can treat it (call it) as a list of dictionaries - which would be what anvil needs. Except when I pass this to the front end from the server, I get an error.
Lastly, I can use pandas dataframes. Though I imagine that the same frontend/backend voodoo will cause issues for me.
In my case, I used this technique in code that runs on a local server to provide data via uplink - but there’s no reason it shouldn’t work within an Anvil server module if marshmallow-sqlalchemy were installed.
Except when I pass this to the front end from the server, I get an error.
What happens if, instead of returning foo, you return list(foo)? That should turn it into a list of dicts, which Anvil can pass very happily from server to client.
You’re right! I completely forgot about RealDictCursor, but now it returns a list of dictionaries which transfer over to the front end without an issue. Thanks
Thanks. That’s useful for me to know. Though Owen reminded me of the RealDictCursor extra in psycopg2 which returns a list of dictionaries natively. For my purposes that is pretty much the best case scenario.