airrecord icon indicating copy to clipboard operation
airrecord copied to clipboard

Table.batch_update

Open aguynamedben opened this issue 5 years ago • 1 comments

This is not ready for merging, but I wanted to submit a proof of concept for https://github.com/sirupsen/airrecord/issues/66 in case somebody else wants to run with it.

This enables an API for Table.batch_update that can take up to 10 existing records (they must already exist in Airtable) and bulk update them with a single API request, as Airtable's API now allows batches of 10 for created, updates, and deletes.

Still needs:

  • Better testing of the Table.batch_update function, but I've seen it working in a project.

Example usage

ben = Seat.find("recMxPcmAqeo7iGj7")
ben["Fun Fact"] = Faker::Music::UmphreysMcgee.song
Seat.batch_update([ben])

Other notes and potential breaking changes:

  • Removes record.hash, I didn't see it being used for anything aside from a test making sure it worked.
  • Removes record.serializable_fields, I didn't see it being used for anything aside from tests, use record.fields instead.
  • Adds record.to_h which gives the record format used in batch operations (i.e. includes id and fields)
  • Adds record.to_h(true) which gives the record format used in batch operations (i.e. includes id and fields), but ONLY includes the updated fields. This can be used for PATCH updates.

Ideal design for this:

  • Airtable now supports batches of 10 for gets, creates, and updates, and deletes. It would be awesome to have a Table.batch_upsert method that accepts up to 10 records, does a multi-get for the 10 records, figures out which ones already exist and don't exist, then runs Test.batch_create for the records that don't exist and Test.batch_update for the records that do exist. Then you could batch import records by just blasting them into Table.batch_upsert.

aguynamedben avatar Apr 18 '20 21:04 aguynamedben

It's too bad you can't finish it, is it because you ended up not needing it in your own project?

sirupsen avatar Apr 19 '20 11:04 sirupsen

Given that the gem is in a rough state I think let's close this for now as it adds more complexity, might be something to revisit in the future.

Meekohi avatar Jan 19 '23 15:01 Meekohi