Removing Soup Elements
Traditionally, SmartStore methods let you remove soup
elements by specifying an array of element IDs. To do so, you usually run a preliminary query to
retrieve the candidate IDs, then call the method that performs the deletion. In Mobile SDK 4.2, SmartStore ups the game by adding a query
option to its element deletion methods. With this option, you provide only a query, and SmartStore deletes all elements that
satisfy that query. This approach delivers a performance boost because both the query and the
deletion operation occur in a single call.
Hybrid Apps
In hybrid apps, you use the
third parameter to pass either an ID array or a SmartStore query spec.
In
addition to success and error callbacks, this function takes the following arguments:
1removeFromSoup([isGlobalStore, ]soupName, entryIdsOrQuerySpec,
2 successCB, errorCB)
3removeFromSoup([storeConfig, ]soupName, entryIdsOrQuerySpec,
4 successCB, errorCB)| Parameter Name | Argument Description |
|---|---|
| isGlobalStore | (Optional) Boolean that indicates whether this operation occurs in a global or user-based SmartStore database. Defaults to false. |
| storeConfig | (Optional) StoreConfig object that specifies a store name and whether the store is global or user-based. |
| soupName | String. Pass in the name of the soup. |
| entryIdsOrQuerySpec | Array or QuerySpec object. Pass in the name of the soup. |
Android Native Apps
Android native methods for removing entries give you the option of either handling the transaction yourself, or letting the method handle the transaction transparently. If you set the handleTx argument to false, you’re responsible for starting the transaction before the call and ending it afterwards. If you use the overload that doesn’t include handleTx, or if you set handleTx to false, Mobile SDK handles the transaction for you.
To remove entries by ID array in Android native apps, call either of the following
methods:
To
remove entries by query in Android native apps, call either of the following
methods:
1public void delete(String soupName, Long... soupEntryIds)
2public void delete(String soupName, Long[] soupEntryIds, boolean handleTx)1public void deleteByQuery(String soupName, QuerySpec querySpec)
2public void deleteByQuery(String soupName, QuerySpec querySpec, boolean handleTx)iOS Native Apps
To remove entries by ID array in iOS native apps, call one of these methods:
Objective-C:
1- (void)removeEntries:(NSArray*)entryIds fromSoup:(NSString*)soupName error:(NSError **)error;Swift:
Example:
1public func remove(entryIds: [Any], forSoupName: String) -> Void1remove(entryIds: entries, forSoupNamed: soupName)To remove entries by query in iOS native apps, call one of these methods:
Objective-C:
1- (void)removeEntriesByQuery:(SFQuerySpec*)querySpec
2 fromSoup:(NSString*)soupName;
3- (void)removeEntriesByQuery:(SFQuerySpec*)querySpec
4 fromSoup:(NSString*)soupName
5 error:(NSError **)error;Swift:
1func remove(usingQuerySpec: QuerySpec, entryIds: [Any], forSoupNamed: String) -> VoidExample:
1var removed = removeEntries(usingQuerySpec: querySpec, forSoupNamed: soupName)