Parse build mobile App backend Service (ii)

Source: Internet
Author: User

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
    1. 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
    1. [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
    1. [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
    1. Pfquery *query = [pfquery querywithclassname:@"Comment"];
    2. [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
    1. Pfquery *innerquery = [pfquery querywithclassname:@"Post"];
    2. [Innerquery wherekeyexists:@"image"];
    3. Pfquery *query = [pfquery querywithclassname:@"Comment"];
    4. [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
    1. Pfquery *lotsofwins = [pfquery querywithclassname:@"Player"];
    2. [Lotsofwins wherekey:@"wins" Greaterthan:[nsnumber Numberwithint:150]];
    3. Pfquery *fewwins = [pfquery querywithclassname:@"Player"];
    4. [Lotsofwins wherekey:@"wins" Lessthan:[nsnumber Numberwithint:5]];
    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
    1. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.