Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

Simple Object Storage
« Anvil Blog
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:

Creating a Simple Object column

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.


Learn More

Get the best out of Anvil with our free email course.