A couple of questions (out of curiosity) I am having trouble working out the answers to:
What if anything would the effect of using an empty q.fetch_only())
Is there a way to invert fetch_only …essentially don’t fetch for columns that you don’t want cached with out typing out all the column names
`q.not_(fetch_only(“non_essential_info_column”))
I am sure I could roll my own using the column names in a list and manipulating a list but wondered if there was a neat option here.
I have tried to verify with timings but I have found it a little difficult to confirm (with out this FR any way )
What if anything would the effect of using an empty q.fetch_only())
This will load a set of references to the rows, but none of the data. This is sometimes useful - eg if you just want to grab all the row IDs, or use them in a query for referenced rows, but don’t care about the data.
This is completely untested, but here is the most concise version I could come up with:
from anvil.tables import app_tables
from anvil.tables import query as q
def q_fetch_none_of(table, column_names_list):
table = getattr(app_tables, table) if isinstance(table, str) else table
for row in table.search(q.page_size(1)):
column_names_list = [x for x in dict(row) if x not in column_names_list]
break
return q.fetch_only(*column_names_list)
Riffing on this (also untested) we could use the table.list_columns() function (docs link) and some list comprehension to do it without the search. Presumably this would handle an empty table.
from anvil.tables import app_tables
from anvil.tables import query as q
def q_fetch_none_of(table, column_names_list):
table = getattr(app_tables, table) if isinstance(table, str) else table
table_columns = [c['name'] for c in table.list_columns()]
column_names_list = [x for x in table_columns if x not in column_names_list]
return q.fetch_only(*column_names_list)
def q_fetch_none_of(table, column_names_list):
table = getattr(app_tables, table) if isinstance(table, str) else table
return q.fetch_only(*[c['name'] for c in table.list_columns() if c['name'] not in column_names_list])
def q_fetch_none_of(table, column_names_to_exclude):
table = (
getattr(app_tables, table) if isinstance(table, str)
else table
)
return q.fetch_only(*[
c['name']
for c in table.list_columns()
if c['name'] not in column_names_to_exclude
])