Fast search and delete row in table

What I’m trying to do:
I’m trying to find a row using a keyword that a user enters and then to delete that entry from stored tables. Is there a quicker way to do it than what I currently have implemented?

table_entry is a dict object.

Code Sample:

@anvil.server.callable
def delete_group(table_entry):
  for iter in app_tables.group_table.search(): 
    if iter["group_name"]==table_entry["Group Name"]:
      iter.delete()
      return

If there’s going to be exactly one with that group name, then use get:

row = app_tables.group_table.get(group_name=table_entry["Group Name"])
if row:
    row.delete()

As much as possible, let the database do the work of finding the right row(s) for you.

4 Likes