Batches [parse.batch]¶
Parse allows batching of certain operations on Objects. You can send up to 50 create, update, or delete calls using the batch method.
.new¶
Create a new batch instance to populate with actions.
local b = parse.batch.new()
.create¶
Add a create
action to the batch instance.
Parameters:
- className
- dataTable
b.create( "Toys", { kind = car, color = red, stock = 23 } )
.update¶
Add an update
action to the batch instance.
Parameters:
- className
- objectId
- dataTable
b.update( "Toys", "123abc", { stock = 20 } )
.delete¶
Add a delete
action to the batch instance.
Parameters:
- className
- objectId
b.delete( "Toys", "123abc" )
.getCount¶
Get the current action count in the batch instance. Parse imposes a 50 action limit per batch transaction.
local action_count = b.getCount()
.getBatch¶
Returns the current batch instance data table for sending to Parse.
local batch_data = b.getBatch()
Example¶
You can mix up to 50 create, update, and delete actions per batch. Batching is limited to Objects only as per the Parse specification.
-- Build the batch local b = parse.batch.new() b.create( "Toys", { kind = car, color = red } ) b.create( "Parts", { wheels = 4 } ) b.update( "Toys", "123abc", { color = blue } ) b.delete( "Parts", "abc123" ) -- Send off the batch parse.request( parse.Object.batch ) :data( b.getBatch() ) :response(function( ok, res ) if not ok then print( 'err', res ) else for _, result in ipairs( res ) do if result.success then print( result.success.createdAt ) else print( result.error.error, result.error.code ) end end end end)
The response is returned in a table array, with the same amount of entry results as sent. Read more about the returns that come back from batch calls by following the link below.