Data types supported by parse
Currently Parse's table column supports NSString, NSNumber, NSDate, NSData, or another pfobject. You can also use Nsdictionary and Nsarray to save structured data. where Nsarray supports the corresponding query. Although you can use NSData to save binary data, it is recommended to save the file with Pffile, such as a photo, and save the Pffile reference in the corresponding column.
Frequently used queries
Like SQL, you create a Pfquery object when you query, and then you set the query criteria.
First look at a simple, query Gamescore table in Playname equals "Dan Stemokoski" all records.
Object C code
- Pfquery *query = [pfquery querywithclassname:@"Gamescore"];[ Query wherekey:@ "playername" equalto:@"Dan Stemkoski"]; Nsarray *objects = [query findobjects];
This is check nsnumber, query playage more than 18 of all records.
Object C code
- [Query wherekey:@"Playerage" Greaterthan:[nsnumber numberwithint:18]];
This is the array, Arymatchtypes is an array of Nsarray, the following statement query Arymatchtypes contains all records of "Football".
Copy Code
Object C code
- [Query wherekey:@ "arymatchtypes" equalto:@"Football"];
Since it is object-oriented, parse also supports associative queries, the following example comment and post are parse objects, and the following code can query all comment records that contain MyPost objects.
Object C code
- Pfquery *query = [pfquery querywithclassname:@"Comment"];
- [Query wherekey:@"POST" equalto:mypost];
Parse supports subqueries, the following example is to find all comments records, where the post contains an image.
Object C code
- Pfquery *innerquery = [pfquery querywithclassname:@"Post"];
- [Innerquery wherekeyexists:@"image"];
- Pfquery *query = [pfquery querywithclassname:@"Comment"];
- [Query wherekey:@"POST" matchesquery:innerquery];
or query, unfortunately, parse does not support or condition queries, supports and only, and can be used with compound query, like the Union of SQL
Object C code
- Pfquery *lotsofwins = [pfquery querywithclassname:@"Player"];
- [Lotsofwins wherekey:@"wins" Greaterthan:[nsnumber Numberwithint:150]];
- Pfquery *fewwins = [pfquery querywithclassname:@"Player"];
- [Lotsofwins wherekey:@"wins" Lessthan:[nsnumber Numberwithint:5]];
- Pfquery *query = [Pfquery orquerywithsubqueries:[nsarray arraywithobjects:fewwins,lotsofwins,nil];
Cache
The result set of the query supports caching, or you can set different cache policies. The cache is at the query level.
Object C code
- Query.cachepolicy = Kpfcachepolicynetworkelsecache;
You can specify the following caching policies:
Kpfcachepolicyignorecache: The query results are from the server and are not saved in the cache. This is the default setting.
Kpfcachepolicycacheonly: Data is only taken from the cache. If the cache does not have data that produces pferror, it can also be ignored without handling the error.
Kpfcachepolicynetworkonly: Data is only taken from the network and stored in the cache.
Kpfcachepolicycacheelsenetwork: Fetch the data from the cache first, if not, then take it from the network.
Kpfcachepolicynetworkelsecache: Take data from the network first, and then from the slow access.
Kpfcachepolicycachethennetwork; Fetch the data from the cache first, no matter how the result will call the callback function query server again. That means 2 calls are generated. The usual use is to quickly take out the data display view, and then back to the background to connect to the network to get the latest data, and then use the latest data from the Web server to update the view. This policy cannot be used with the Findobjects method, only with the findobjectsinbackground of the asynchronous call.
The sixth strategy leads to one of the main features of parse: Background asynchronous invocation, which is also a frequently needed solution for iOS web App development, which allows users to not be stunned by the sight of a motionless screen after pressing a button. Parse provides a variety of solutions that are available to talk about. Share to:
Parse build mobile App backend Service (ii)