Updating Multiple Objects¶
This API updates multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which updates all objects in the Person
data table where the value of the property age
is greater than 20
. As a result of the request, all updated objects will have the contactType
property set to "personal"
:
MapDrivenDataStore *dataStore = [Backendless.shared.data ofTable:@"Person"];
NSDictionary *changes = @{@"contactType": @"personal"};
[dataStore updateBulkWithWhereClause:@"age>20" changes:changes responseHandler:^(NSNumber *updated) {
NSLog(@"%@ objects have been updated", updated);
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
let dataStore = Backendless.shared.data.ofTable("Person")
let changes = ["contactType": "personal"]
dataStore.updateBulk(whereClause: "age>20", changes: changes, responseHandler: { updated in
print("\(updated) objects have been updated")
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
Available methods¶
- (void)updateBulkWithWhereClause:(NSString * _Nullable)whereClause changes:(NSDictionary<NSString *,id> * _Nonnull)changes responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func updateBulk(whereClause: String?, changes: [String : Any], responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)
- (void)updateBulkWithWhereClause:(NSString * _Nullable)whereClause changes:(NSDictionary<NSString *,id> * _Nonnull)changes responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func updateBulk(whereClause: String?, changes: [String : Any], responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)
where:
Argument | Description |
---|---|
whereClause |
a condition for selecting objects in the data table which will be updated. |
changes |
a dictionary object containing the changes which will be applied to all objects in the data table which match the condition expressed via whereClause . |
responseHandler |
a block (closure) to handle successful result of an asynchronous call. |
errorHandler |
a block (closure) fault result of an asynchronous call. |
Return Value¶
The API returns the number of objects updated in the database as a result of the request.