Hi,
It is possible to get values from ONE particular column, however it is not clear how to get values from several ones. Any help is greatly appreciated.
names = [r['name'] for r in app_tables.people.search()]
Hi,
It is possible to get values from ONE particular column, however it is not clear how to get values from several ones. Any help is greatly appreciated.
names = [r['name'] for r in app_tables.people.search()]
Adapted from an actual application:
result = [
{
'user_descr': row["user_descr"],
'report_type_name': row["report_type_name"],
'has_csv_data': row["has_csv_data"],
}
for row in app_tables.reports.search()
]
Result is a list
of dict
s, compatible with Anvilās items
.
You might also upvote this feature request: Client-readable views on a subset of columns
The feature request would allow us to select individual columns to be returned from a search. This would prevent the need to do a list comprehension over the entire results.
You could also have a look at my serialiser:
Yes, nice solution. This actually helped me out when stuck on returning some rows for a few hours, so it is in my code now. Thank you.
I was wondering if using this query makes multiple calls to the server?
Iām currently working on adding that serialiser to anvil-extras. Almost thereā¦
If you run this code on the client, Anvil will do its best trying to load chunks of database rather than a little bit at a time.
For example it could decide to read 10 rows on each round trip leaving behind the simple object columns to save bandwidth. This could be good for you, but if you need simple object values or you need the 11th row, you would trigger more round trips.
I never return rows to the client for this reason, because I donāt have control over the number of round trips. I always do my dictionary comprehensions on the server side and return a list of dictionaries to the client, so Iām sure I do only one round trip which includes all and only the data I need. Now the problem is that I return a list, not a generator, so I need to return all the rows I need in one round trip.
This feature request addresses this very problem, you can upvote it.