Android
Data objects
Parse on Androidでのすべてのクエリ手法の使用方法
22 分
androidにおけるparse query cookbook はじめに 私たちはすでに、 parsequery parsequery を使用して、 get get でback4appから単一の parsequery parsequery を取得する方法を見てきました。他にも、 parsequery parsequery を使用して、複数のオブジェクトを一度に取得したり、取得したいオブジェクトに条件を適用したりする方法がたくさんあります。 このガイドでは、 parsequery parsequery クラスを深く掘り下げ、クエリを構築するために使用できるすべてのメソッドを確認します。簡単なデータベースクラスといくつかのモックデータを使用して、back4appのjavascriptコンソールを使用してクエリを実行します。 back4appのjavascriptコンソールを使用して簡単にモックデータを作成できます。または、 このガイド に従って、自分のandroidアプリでデータを作成することもできます。 このチュートリアルは、 buildtoolsversion=30 0 2 buildtoolsversion=30 0 2 、 compile sdk version = 30 0 2 compile sdk version = 30 0 2 、および targetsdkversion=30 targetsdkversion=30 いつでも、このチュートリアルで構築された完全なandroidプロジェクトに、私たちのgithubリポジトリでアクセスできます。 kotlinの例リポジトリ javaの例リポジトリ 前提条件 このチュートリアルを完了するには、次のものが必要です: android studio back4appで作成されたアプリ。 注: 新しいparseアプリのチュートリアル を参照して、back4appでparseアプリを作成する方法を学んでください。 back4appに接続されたandroidアプリ。 注: parse sdkのインストールチュートリアル を参照して、back4appに接続されたandroid studioプロジェクトを作成してください。 android 4 1(jelly bean)以上を実行しているデバイス(または 仮想デバイス )。 目標 次のことを探求します: parsequery parsequery クラスのさまざまなメソッドと、androidで作成できるクエリタイプを学びます。 parsequeryクラス parseでの任意のクエリ操作は、 parsequery parsequery オブジェクトタイプを使用し、アプリ全体でback4appから特定のデータを取得するのに役立ちます。新しい parsequery parsequery を作成するには、取得したい parsequery parsequery サブクラスをパラメータとして渡す必要があります。これは、クエリ結果を含むものです。 重要なのは、 parsequery parsequery は、retrieveメソッド(例えば、 parsequery find parsequery find や parsequery get parsequery get )を呼び出した後にのみ解決されることを知っておくことが重要です。したがって、クエリを設定し、実際に呼び出される前にいくつかの修飾子をチェーンすることができます。 公式ドキュメントの parsequery parsequery クラスについての詳細は、 こちらの公式ドキュメントで https //parseplatform org/parse sdk android/api/ ご覧いただけます。 back4appでのjsコンソールの使用 back4appアプリケーションのダッシュボード内には、javascriptコードを直接実行できる非常に便利なapiコンソールがあります。このガイドでは、back4appからデータオブジェクトを保存およびクエリするために使用します。アプリのメインダッシュボードで、 core >api console >js console。 core >api console >js console。 データオブジェクトを保存する このガイドでクエリを実行するには、まずアプリにいくつかのデータを入力する必要があります。サンプルクラスとして、 profile profile を作成します。これは、有名人の名前と以下のフィールドを使用してソーシャルメディアプロファイルクラスを模倣します。 文字列型 日付型 数値(整数)型 配列(文字列配列)型 配列(数値配列)型 geopoint型 ヌル可能ポインタ型 ここに parse object parse object クラスの作成コードがありますので、apiコンソールで実行してください 1 // add profile objects and create table 2 // adam sandler 3 let profile = new parse object('profile'); 4 profile set('name', 'adam sandler'); 5 profile set('birthday', new date('09/09/1966')); 6 profile set('friendcount', 2); 7 profile set('favoritefoods', \['lobster', 'bread']); 8 profile set('luckynumbers', \[2, 7]); 9 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 10 await profile save(); 11 12 // britney spears 13 profile = new parse object('profile'); 14 profile set('name', 'britney spears'); 15 profile set('birthday', new date('12/02/1981')); 16 profile set('friendcount', 52); 17 profile set('favoritefoods', \['cake', 'bread']); 18 profile set('luckynumbers', \[22, 7]); 19 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 20 await profile save(); 21 22 // carson kressley 23 profile = new parse object('profile'); 24 profile set('name', 'carson kressley'); 25 profile set('birthday', new date('11/11/1969')); 26 profile set('friendcount', 12); 27 profile set('favoritefoods', \['fish', 'cookies']); 28 profile set('luckynumbers', \[8, 2]); 29 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 30 await profile save(); 31 32 // dan aykroyd 33 // creates related object membership for this user only 34 let membership = new parse object('membership'); 35 membership set('name', 'premium'); 36 membership set('expirationdate', new date('10/10/2030')) 37 await membership save(); 38 profile = new parse object('profile'); 39 profile set('name', 'dan aykroyd'); 40 profile set('birthday', new date('07/01/1952')); 41 profile set('friendcount', 66); 42 profile set('favoritefoods', \['jam', 'peanut butter']); 43 profile set('luckynumbers', \[22, 77]); 44 profile set('lastloginlocation', new parse geopoint(37 38412167489413, 122 01268034622319)); 45 profile set('premiummembership', membership); 46 await profile save(); 47 48 // eddie murphy 49 profile = new parse object('profile'); 50 profile set('name', 'eddie murphy'); 51 profile set('birthday', new date('04/03/1961')); 52 profile set('friendcount', 49); 53 profile set('favoritefoods', \['lettuce', 'pepper']); 54 profile set('luckynumbers', \[6, 5]); 55 profile set('lastloginlocation', new parse geopoint( 27 104919974838154, 52 61428045237739)); 56 await profile save(); 57 58 // fergie 59 profile = new parse object('profile'); 60 profile set('name', 'fergie'); 61 profile set('birthday', new date('03/27/1975')); 62 profile set('friendcount', 55); 63 profile set('favoritefoods', \['lobster', 'shrimp']); 64 profile set('luckynumbers', \[13, 7]); 65 profile set('lastloginlocation', new parse geopoint( 27 104919974838154, 52 61428045237739)); 66 await profile save(); 67 68 console log('success!'); このコードを実行した後、データベースに profile profile クラスが作成され、6つのオブジェクトが生成されているはずです。新しいクラスは次のようになります 次に、すべての parsequery parsequery メソッドの例を見て、それぞれの機能について簡単に説明します。このリストのいくつかのメソッドは options options を追加の引数として受け取ることができますが、ほとんどの場合、それは masterkey masterkey の使用に関連しており、このガイドの内容には関係ないため、関連性がない場合はこの可能性を省略します。 クエリリトリーバー これらのメソッドは、クエリを実行し、その結果を取得する責任があり、常にクエリの実装に存在します。 これは java メソッドです cancel //cancels the current network request 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query findinbackground(); 3 query cancel(); count //retrieves the count of parseobject results that meet the query criteria 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 try { 3 int querycount = query count(); 4 log d(tag, "count " + querycount); 5 } catch (com parse parseexception parseexception) { 6 parseexception printstacktrace(); 7 } find //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works synchronously 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 try { 4 list\<parseobject> list = query find(); 5 log d(tag, "list " + list); 6 } catch (com parse parseexception e) { 7 e printstacktrace(); 8 } findinbackground //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works asynchronously 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parseerror ", e); 8 } 9 }); first //retrieves the first parseobject instance that meets the query criteria 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 try { 3 parseobject firstitem = query getfirst(); 4 log d(tag, "first item " + firstitem); 5 } catch (parseexception e) { 6 e printstacktrace(); 7 } get //this quick method is used to retrieve a single parseobject instance when you know its objectid 1 //we can call a parse object with an object id with the get() function 2 parsequery\<parseobject> query = new parsequery<>("profile"); 3 try { 4 parseobject object = query get("c6endlnfdq"); 5 log d(tag, "object " + object); 6 } catch (parseexception e) { 7 e printstacktrace(); 8 } これは kotlin メソッドです cancel //cancels the current network request 1 val query = parsequery\<parseobject>("profile") 2 query findinbackground() 3 query cancel() count //retrieves the count of parseobject results that meet the query criteria 1 val query = parsequery\<parseobject>("profile") 2 try { 3 val querycount = query count() 4 log d(companion tag, "count $querycount") 5 } catch (parseexception parseexception) { 6 parseexception printstacktrace() 7 } find //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works synchronously 2 val query = parsequery\<parseobject>("profile") 3 try { 4 val list = query find() 5 log d(companion tag, "list $list") 6 } catch (e parseexception) { 7 e printstacktrace() 8 } findinbackground //this is the basic method for retrieving your query results, always returning an array of parseobject instances, being empty when none are found 1 //this find function works asynchronously 2 val query = parsequery\<parseobject>("profile") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parseerror ", e) 8 } 9 } first //retrieves the first parseobject instance that meets the query criteria 1 val query = parsequery\<parseobject>("profile") 2 try { 3 val firstitem = query first 4 log d(companion tag, "first item $firstitem") 5 } catch (e parseexception) { 6 e printstacktrace() 7 } get //this quick method is used to retrieve a single parseobject instance when you know its objectid 1 //we can call a parse object with an object id with the get() function 2 val query = parsequery\<parseobject>("profile") 3 try { 4 val `object` = query\["c6endlnfdq"] 5 log d(companion tag, "object $`object`") 6 } catch (e parseexception) { 7 e printstacktrace() 8 } クエリ条件 これらのメソッドは、クエリに条件付き制約を適用する可能性を提供します。これは、クエリにおいて最も重要な操作といえるでしょう。これらの操作はすべて、結果が取得される前にチェーンすることができるため、クエリのニーズを解決するために多くの組み合わせを実現できます。 これらは java メソッドです containedin //filters objects in which a key value is contained in the provided array of values 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainedin("luckynumbers", list of(2, 7)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); contains //filters objects in which a string key value contains the provided text value be aware that this condition is case sensitive 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontains("name", "da"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); cointansall //filters objects in which an array type key value must contain every value provided 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainsall("luckynumbers", list of(2, 7)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); containsallstartingwith //filters objects in which an array type key value must contain every string value provided 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherecontainsallstartswith("favoritefoods", list of("shrimp", "lobster")); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); doesnotexist //filters objects in which a key value is not set 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wheredoesnotexist("premiummembership"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); これらは kotlin メソッドです containedin //filters objects in which a key value is contained in the provided array of values 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainedin("luckynumbers", java util list of(2, 7)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } contains //filters objects in which a string key value contains the provided text value be aware that this condition is case sensitive 1 val query = parsequery\<parseobject>("profile") 2 query wherecontains("name", "da") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } cointansall //filters objects in which an array type key value must contain every value provided 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainsall("luckynumbers", java util list of(2, 7)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } containsallstartingwith //filters objects in which an array type key value must contain every string value provided 1 val query = parsequery\<parseobject>("profile") 2 query wherecontainsallstartswith("favoritefoods", java util list of("shrimp", "lobster")) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } doesnotexist //filters objects in which a key value is not set 1 val query = parsequery\<parseobject>("profile") 2 query wheredoesnotexist("premiummembership") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } これらは java メソッドです canceldoesnotmatchkeyinquery //requires that a key’s value does not match a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("profile"); 3 innerquery wherelessthan("friendcount", 50); 4 query wheredoesnotmatchkeyinquery("friendcount", "friendcount", innerquery); 5 query wheregreaterthan("friendcount", 10); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); doesnotmatchquery //requires that an object contained in the given key does not match another query useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("membership"); 3 innerquery wheregreaterthan("expirationdate", new date()); 4 query whereexists("premiummembership"); 5 query wheredoesnotmatchquery("premiummembership", innerquery); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); endswith //filters objects in which a string key’s value ends with the provided text value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereendswith("name", "ie"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); equalto //filters objects in which a specific key’s value is equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereequalto("friendcount", 2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); exists //filters objects in which a key value is set 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereexists("premiummembership"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); fulltext //filters objects in which a string key’s value wrap matches the provided text value in it it can have many customizable options to improve its results, like language specification and score order 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherefulltext("name", "spears"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); greaterthan //filters objects in which a specific key’s value is greater than the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 calendar calendar = calendar getinstance(); 3 calendar set(1980, 8, 19, 59, 59, 59); 4 date date = calendar gettime(); 5 query wheregreaterthan("birthday", date); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); greaterthanorequalto //filters objects in which a specific key’s value is greater than or equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wheregreaterthanorequalto("friendcount", 49); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); これらは kotlin メソッドです canceldoesnotmatchkeyinquery //requires that a key’s value does not match a value in an object returned by a different parsequery useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("profile") 3 innerquery wherelessthan("friendcount", 50) 4 query wheredoesnotmatchkeyinquery("friendcount", "friendcount", innerquery) 5 query wheregreaterthan("friendcount", 10) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } doesnotmatchquery //requires that an object contained in the given key does not match another query useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("membership") 3 innerquery wheregreaterthan("expirationdate", date()) 4 query whereexists("premiummembership") 5 query wheredoesnotmatchquery("premiummembership", innerquery) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } endswith //filters objects in which a string key’s value ends with the provided text value 1 val query = parsequery\<parseobject>("profile") 2 query whereendswith("name", "ie") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } equalto //filters objects in which a specific key’s value is equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query whereequalto("friendcount", 2) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } exists //filters objects in which a key value is set 1 val query = parsequery\<parseobject>("profile") 2 query whereexists("premiummembership") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } fulltext //filters objects in which a string key’s value wrap matches the provided text value in it it can have many customizable options to improve its results, like language specification and score order 1 val query = parsequery\<parseobject>("profile") 2 query wherefulltext("name", "spears") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } greaterthan //filters objects in which a specific key’s value is greater than the provided value 1 val query = parsequery\<parseobject>("profile") 2 val calendar = calendar getinstance() 3 calendar\[1980, 8, 19, 59, 59] = 59 4 val date = calendar time 5 query wheregreaterthan("birthday", date) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } greaterthanorequalto //filters objects in which a specific key’s value is greater than or equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wheregreaterthanorequalto("friendcount", 49) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } これらは java メソッドです lessthan //filters objects in which a specific key’s value is lesser than the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 calendar calendar = calendar getinstance(); 3 calendar set(1980, 8, 19, 59, 59, 59); 4 date date = calendar gettime(); 5 query wherelessthan("birthday", date); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); lessthanorequalto //filters objects in which a specific key’s value is lesser than or equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherelessthanorequalto("friendcount", 49); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); matches //filters objects in which a string type key value must match the provided regular expression and its modifiers 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherematches("name", "da", "i"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); matcheskeyinquery //requires that a key’s value matches a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("profile"); 3 innerquery wherelessthan("friendcount", 50); 4 query wherematcheskeyinquery("friendcount", "friendcount", innerquery); 5 query wheregreaterthan("friendcount", 10); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); matchesquery //requires that an object contained in the given key matches another query useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 parsequery\<parseobject> innerquery = new parsequery<>("membership"); 3 innerquery wheregreaterthan("expirationdate", new date()); 4 query whereexists("premiummembership"); 5 query wherematchesquery("premiummembership", innerquery); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 }); notequalto //filters objects in which a specific key’s value is not equal to the provided value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherenotequalto("friendcount", 2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); startswith //filters objects in which a string key’s value starts with the provided text value 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherestartswith("name", "brit"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); これらは kotlin メソッドです lessthan //filters objects in which a specific key’s value is lesser than the provided value 1 val query = parsequery\<parseobject>("profile") 2 val calendar = calendar getinstance() 3 calendar\[1980, 8, 19, 59, 59] = 59 4 val date = calendar time 5 query wherelessthan("birthday", date) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } lessthanorequalto //filters objects in which a specific key’s value is lesser than or equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wherelessthanorequalto("friendcount", 49) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } matches //filters objects in which a string type key value must match the provided regular expression and its modifiers 1 val query = parsequery\<parseobject>("profile") 2 query wherematches("name", "da", "i") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } matcheskeyinquery //requires that a key’s value matches a value in an object returned by a different parsequery useful for multi object querying 1 parsequery\<parseobject> query = new parsequery<>("profile"); 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("profile") 3 innerquery wherelessthan("friendcount", 50) 4 query wherematcheskeyinquery("friendcount", "friendcount", innerquery) 5 query wheregreaterthan("friendcount", 10) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } matchesquery //requires that an object contained in the given key matches another query useful for multi object querying 1 val query = parsequery\<parseobject>("profile") 2 val innerquery = parsequery\<parseobject>("membership") 3 innerquery wheregreaterthan("expirationdate", date()) 4 query whereexists("premiummembership") 5 query wherematchesquery("premiummembership", innerquery) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } notequalto //filters objects in which a specific key’s value is not equal to the provided value 1 val query = parsequery\<parseobject>("profile") 2 query wherenotequalto("friendcount", 2) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } startswith //filters objects in which a string key’s value starts with the provided text value 1 val query = parsequery\<parseobject>("profile") 2 query wherestartswith("name", "brit") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } クエリの順序 ほとんどのクエリにおいて不可欠であり、parseでは簡単に順序付けが可能で、2つ以上の順序制約の間で連鎖させることもできます。 これらは java メソッドです addascending //sort the results in ascending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query addascendingorder("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); adddescending //sort the results in descending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query adddescendingorder("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); ascending //sort the results in ascending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query orderbyascending("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); descending //sort the results in descending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query orderbydescending("friendcount"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); これらは kotlin メソッドです addascending //sort the results in ascending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query addascendingorder("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } adddescending //sort the results in descending order, overwrites previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query adddescendingorder("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } ascending //sort the results in ascending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query orderbyascending("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } descending //sort the results in descending order, this can be chained without overwriting previous orderings multiple keys can be used to solve ordering ties 1 val query = parsequery\<parseobject>("profile") 2 query orderbydescending("friendcount") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } フィールド選択 これらのメソッドは、クエリ結果に含まれるフィールド値に影響を与えます。 これらは java メソッドです include //return all fields in the returned objects except the ones specified 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query whereexists("premiummembership"); 3 query include("premiummembership"); 4 query findinbackground((objects, e) > { 5 if (e == null) { 6 log d(tag, "objects " + objects); 7 log d(tag, "object premium membership " + objects get(0) get("premiummembership")); 8 } else { 9 log e(tag, "parse error ", e); 10 } 11 12 }); select //return only the specified fields in the returned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query selectkeys(list of("name")); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 log d(tag, "object name " + objects get(0) get("name")); 7 } else { 8 log e(tag, "parse error ", e); 9 } 10 11 }); これらは kotlin メソッドです include //return all fields in the returned objects except the ones specified 1 val query = parsequery\<parseobject>("profile") 2 query whereexists("premiummembership") 3 query include("premiummembership") 4 query findinbackground { objects list\<parseobject>, e parseexception? > 5 if (e == null) { 6 log d(companion tag, "objects $objects") 7 log d( 8 companion tag, 9 "object premium membership " + objects\[0]\["premiummembership"] 10 ) 11 } else { 12 log e(companion tag, "parse error ", e) 13 } 14 } select //return only the specified fields in the returned objects 1 val query = parsequery\<parseobject>("profile") 2 query selectkeys(java util list of("name")) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 log d(companion tag, "object name " + objects\[0]\["name"]) 7 } else { 8 log e(companion tag, "parse error ", e) 9 } 10 } ジオポイントクエリ これらはジオポイントクエリに特有のメソッドです。 これらは java メソッドです near //order objects by how near the key value is from the given geopoint 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherenear("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); polygoncontains //find objects whose key value contains the specified geopoint 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherepolygoncontains("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withingeobox //find objects whose key value is contained within the specified bounding box, composed by two geopoint values that set the lower left and upper right corner values 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithingeobox("lastloginlocation", new parsegeopoint(37 48412167489413, 122 11268034622319), new parsegeopoint(37 28412167489413, 121 91268034622319)); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinkilometers //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinkilometers("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinmiles //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinmiles("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); withinpolygon //find objects whose key value is contained within the specified polygon, composed of an array of geopoints (at least three) if the polygon path is open, it will be closed automatically by parse connecting the last and first points 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinpolygon("lastloginlocation", list of(new parsegeopoint(37 48412167489413, 122 11268034622319), 3 new parsegeopoint(37 48412167489413, 121 91268034622319), 4 new parsegeopoint(37 28412167489413, 121 91268034622319), 5 new parsegeopoint(37 28412167489413, 122 01268034622319))); 6 query findinbackground((objects, e) > { 7 if (e == null) { 8 log d(tag, "objects " + objects); 9 } else { 10 log e(tag, "parse error ", e); 11 } 12 13 }); withinradians //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query wherewithinradians("lastloginlocation", new parsegeopoint(37 38412167489413, 122 01268034622319), 100); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); これらは kotlin メソッドです near //order objects by how near the key value is from the given geopoint 1 val query = parsequery\<parseobject>("profile") 2 query wherenear("lastloginlocation", parsegeopoint(37 38412167489413, 122 01268034622319)) 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } polygoncontains //find objects whose key value contains the specified geopoint 1 val query = parsequery\<parseobject>("profile") 2 query wherepolygoncontains( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319) 5 ) 6 query findinbackground { objects list\<parseobject>, e parseexception? > 7 if (e == null) { 8 log d(companion tag, "objects $objects") 9 } else { 10 log e(companion tag, "parse error ", e) 11 } 12 } withingeobox //find objects whose key value is contained within the specified bounding box, composed by two geopoint values that set the lower left and upper right corner values 1 val query = parsequery\<parseobject>("profile") 2 query wherewithingeobox( 3 "lastloginlocation", 4 parsegeopoint(37 48412167489413, 122 11268034622319), 5 parsegeopoint(37 28412167489413, 121 91268034622319) 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinkilometers //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinkilometers( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinmiles //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinmiles( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } withinpolygon //find objects whose key value is contained within the specified polygon, composed of an array of geopoints (at least three) if the polygon path is open, it will be closed automatically by parse connecting the last and first points 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinpolygon( 3 "lastloginlocation", java util list of( 4 parsegeopoint(37 48412167489413, 122 11268034622319), 5 parsegeopoint(37 48412167489413, 121 91268034622319), 6 parsegeopoint(37 28412167489413, 121 91268034622319), 7 parsegeopoint(37 28412167489413, 122 01268034622319) 8 ) 9 ) 10 query findinbackground { objects list\<parseobject>, e parseexception? > 11 if (e == null) { 12 log d(companion tag, "objects $objects") 13 } else { 14 log e(companion tag, "parse error ", e) 15 } 16 } withinradians //find objects whose key value is near the given geopoint and within the maxdistance value the sorted boolean value determines if the results should be sorted by distance ascending 1 val query = parsequery\<parseobject>("profile") 2 query wherewithinradians( 3 "lastloginlocation", 4 parsegeopoint(37 38412167489413, 122 01268034622319), 5 100 0 6 ) 7 query findinbackground { objects list\<parseobject>, e parseexception? > 8 if (e == null) { 9 log d(companion tag, "objects $objects") 10 } else { 11 log e(companion tag, "parse error ", e) 12 } 13 } ページネーション これらのメソッドは、結果が大量に取得されるクエリに役立つページネーションユーティリティに関連しています。 これらは java メソッドです limit //sets the maximum value of returned results, the default value is 100 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query setlimit(2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); skip //skips the first n results in the query, essential for pagination 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query setskip(2); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); これらは kotlin メソッドです limit //sets the maximum value of returned results, the default value is 100 1 val query = parsequery\<parseobject>("profile") 2 query limit = 2 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } skip //skips the first n results in the query, essential for pagination 1 val query = parsequery\<parseobject>("profile") 2 query skip = 2 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } ローカルデータストア これらのメソッドは、クエリのソースを選択し、ローカルデータストアを使用することを可能にします。 これらは java メソッドです fromlocaldatastore //changes the source of this query to all pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 //if you want use localdatastore you should enable local data store in the app java or app kt file 3 query fromlocaldatastore(); 4 query findinbackground((objects, e) > { 5 if (e == null) { 6 log d(tag, "objects " + objects); 7 } else { 8 log e(tag, "parse error ", e); 9 } 10 11 }); fromnetwork //changes the source of this query to your online server 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query fromnetwork(); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); frompin //changes the source of this query to the default group of pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query frompin(); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 10 }); frompinwithname //changes the source of this query to a specific group of pinned objects 1 parsequery\<parseobject> query = new parsequery<>("profile"); 2 query frompin("pinnedobjects"); 3 query findinbackground((objects, e) > { 4 if (e == null) { 5 log d(tag, "objects " + objects); 6 } else { 7 log e(tag, "parse error ", e); 8 } 9 }); これらは kotlin メソッドです fromlocaldatastore //changes the source of this query to all pinned objects 1 val query = parsequery\<parseobject>("profile") 2 //if you want use localdatastore you should enable local data store in the app java or app kt file 3 query fromlocaldatastore() 4 query findinbackground { objects list\<parseobject>, e parseexception? > 5 if (e == null) { 6 log d(companion tag, "objects $objects") 7 } else { 8 log e(companion tag, "parse error ", e) 9 } 10 } fromnetwork //changes the source of this query to your online server 1 val query = parsequery\<parseobject>("profile") 2 query fromnetwork() 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } frompin //changes the source of this query to the default group of pinned objects 1 val query = parsequery\<parseobject>("profile") 2 query frompin() 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } frompinwithname //changes the source of this query to a specific group of pinned objects 1 val query = parsequery\<parseobject>("profile") 2 query frompin("pinnedobjects") 3 query findinbackground { objects list\<parseobject>, e parseexception? > 4 if (e == null) { 5 log d(companion tag, "objects $objects") 6 } else { 7 log e(companion tag, "parse error ", e) 8 } 9 } 結論 このガイドの最後に、androidで異なるクエリタイプを使用する方法を学びました。