New: Store richer data in Data Tables

Do you find yourself wanting to store more than just strings, numbers and dates in your tables? Perhaps you have complex records with dynamic fields, or perhaps you want to store lists of data without making a whole new table.

Today, we’re introducing a new type of column: the Simple Object. It can store lists, dicts, numbers, strings and (of course) None. (If you’re familiar with JSON, you’ll know this is another way of saying “any JSON value”.)

Add a Simple Object column to your table like this:

Note: This guide includes screenshots of the Classic Editor. Since we created this guide, we've released the new Anvil Editor, which is more powerful and easier to use.

All the code in this guide will work, but the Anvil Editor will look a little different to the screenshots you see here!


Now you can store structured data in a single row of your table:

app_tables.people.add_row(
name = "Kermit the Frog",
contact_details = {
  'phone': [
    {'type': 'work',
     'number': '555-555-5555'},
    {'type': 'home',
     'number': '555-123-4567'}
  ]
})

Querying them is just as simple. If you supply an object to the Data Tables search() or get() method, you’ll match every value that contains those values, dictionary keys or list items. Here’s an example:

def get_person_for_number(phone_number):
# We have a phone call for this number. Who is it?
    return app_tables.people.get(
		contact_details = {'phone': [{'number': phone_number}]}
	)

You can read more about Simple Object columns in the Data Tables reference docs.