It would be extremely helpful if there was more ability for introspection with Row objects.
For example, we often want to verify that a row is a member of a table:
tables = (app_tables.table_1, app_tables.table_2, app_tables.table_3)
# current implementation
has_row = any((table.has_row(row) for table in tables))
# Desired implementation
has_row = row.get_table() in tables
The second is more readable. I also assume that has_row
requires a trip to the database (could be wrong), so it would also be more efficient.
It would also be helpful to be able to type-check Row objects. Right now the best workaround is to use anvil.LiveObjectProxy
client-side and anvil._server.LiveObjectProxy
server-side, but we can’t then differentiate between row objects and search iterators (or other proxies), without using hasattr
as well.
row = app_tables.table_1.get()
# Current implementation
isinstance(row, app_tables.Row) # resolves to False
# Desired implementation
isinstance(row, app_tables.Row) # resovles to True, client-side or server-side
Finally it would be helpful to be able to type-hint row objects specific to a table:
# current implementation
def get_user(email: str): -> anvil.tables.Row
return app_tables.users.get_user(email=email)
# desired implementation (probably not exact but something like this)
def get_user(email: str): -> app_tables.users.Row
return app_tables.users.get_user(email=email)
Related: Working with Table and Row objects?