Spatial Data Delete API¶
There are two way to delete a spatial value from an object in the database:
- Using Backendless Console
- Using API
Deleting Data with Console¶
To delete a spatial value in console, simply clear out the contents of a cell and press Enter
. Backendless Console confirms that the object has been updated:
Deleting Data with the API¶
Deleting a spatial value from an object using the API is technically the object update operation with the spatial value property set to null
. The following algorithm can be used to perform deletion:
- Retrieve from the database the data object which contains the spatial property to be deleted.
- Set the property value to
null
. - Save the object back in the database.
The example below demonstrates the approach:
Person class:
@interface Person : NSObject
@property (strong, nonatomic) BLPoint *location;
@end
[[Backendless.shared.data of:[Person class]] findFirstWithResponseHandler:^(Person *firstPerson) {
firstPerson.location = nil;
[[Backendless.shared.data of:[Person class]] saveWithEntity:firstPerson responseHandler:^(NSDictionary *response) {
// location has been deleted
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
Building class:
@objcMembers class Building: NSObject {
var objectId: String?
var name: String?
var shape: BLPolygon?
}
[[Backendless.shared.data of:[Person class]] findFirstWithResponseHandler:^(Person *firstPerson) {
firstPerson.location = nil;
[[Backendless.shared.data of:[Person class]] saveWithEntity:firstPerson responseHandler:^(NSDictionary *response) {
// location has been deleted
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
[[Backendless.shared.data ofTable:@"Person"] findFirstWithResponseHandler:^(NSDictionary *firstPerson) {
NSMutableDictionary *person = [firstPerson mutableCopy];
person[@"location"] = [NSNull null];
[[Backendless.shared.data ofTable:@"Person"] saveWithEntity:person responseHandler:^(NSDictionary *response) {
// location has been deleted
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.data.ofTable("Person").findFirst(responseHandler: { firstPerson in
var firstPerson = firstPerson
firstPerson["location"] = NSNull()
Backendless.shared.data.ofTable("Person").save(entity: firstPerson, responseHandler: { response in
// location has been deleted
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
Alternatively, the same result can be achieved using the bulk update API operation. With this approach you can delete a spatial property either in a single or multiple objects. This is done with a query (the where clause) used in the API request. For example, the following query uniquely identifies a single object: objectId = 'XXX-XXX-XXX'
. Consider an example demonstrating the approach:
NSString *whereClause = @"email = 'bob@thebuilder.com'";
NSDictionary *changes = @{@"location": [NSNull null]};
[[Backendless.shared.data ofTable:@"Person"] updateBulkWithWhereClause:whereClause changes:changes responseHandler:^(NSInteger objectsUpdated) {
// objectsUpdated is how many objects were updated by the API call
} errorHandler:^(Fault *fault) {
NSLog(@"Error: %@", fault.message);
}];
let whereClause = "email = 'bob@thebuilder.com'"
let changes = ["location": NSNull()]
Backendless.shared.data.ofTable("Person").updateBulk(whereClause: whereClause, changes: changes, responseHandler: { objectsUpdated in
// objectsUpdated is how many objects were updated by the API call
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})