airrecord
airrecord copied to clipboard
Table.batch_update
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, userecord.fieldsinstead. - Adds
record.to_hwhich gives the record format used in batch operations (i.e. includesidandfields) - Adds
record.to_h(true)which gives the record format used in batch operations (i.e. includesidandfields), 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.
It's too bad you can't finish it, is it because you ended up not needing it in your own project?
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.