Android
Data objects
Методы ParseQuery в Android: Полное руководство
23 мин
кулинарная книга запросов parse в android введение мы уже видели, как parsequery parsequery с помощью get get может извлекать один parsequery parsequery из back4app существует множество других способов извлечения данных с помощью parsequery parsequery , вы можете извлекать множество объектов сразу, использовать условия для объектов, которые вы хотите извлечь, и многое другое в этом руководстве вы глубоко погрузитесь в класс parsequery parsequery и увидите все методы, которые вы можете использовать для построения ваших запросов вы будете использовать простой класс базы данных с некоторыми смоделированными данными для выполнения запросов с помощью консоли javascript на back4app вы можете использовать консоль javascript на back4app для легкого создания смоделированных данных, или вы можете создать свои данные с помощью вашего собственного android приложения, следуя этому руководству этот учебник использует приложение, созданное в android studio 4 1 1 с 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 app чтобы узнать, как создать parse app на back4app android приложение, подключенное к back4app примечание следуйте за руководством по установке parse sdk чтобы создать проект android studio, подключенный к back4app устройство (или виртуальное устройство ) с android 4 1 (jelly bean) или новее цель изучите класс parsequery parsequery и его различные методы, а также узнайте о типах запросов, которые вы можете создать на android класс parsequery любая операция запроса в parse использует тип объекта parsequery parsequery , который поможет вам извлекать конкретные данные из вашего back4app на протяжении всего вашего приложения чтобы создать новый parsequery parsequery , вам нужно передать в качестве параметра желаемый parsequery parsequery подкласс, который будет содержать результаты вашего запроса крайне важно знать, что parsequery parsequery будет разрешен только после вызова метода извлечения (например, parsequery find parsequery find или parsequery get parsequery get ), поэтому запрос может быть настроен, и несколько модификаторов могут быть связаны перед фактическим вызовом вы можете узнать больше о классе parsequery parsequery здесь в официальной документации https //parseplatform org/parse sdk android/api/ использование js console на back4app в панели управления вашим приложением back4app вы найдете очень полезную api консоль, в которой вы можете запускать код javascript напрямую в этом руководстве вы будете использовать ее для хранения и запроса объектов данных из back4app на главной панели вашего приложения перейдите в core >api console >js console core >api console >js console сохраните ваши объекты данных чтобы выполнить запросы в этом руководстве, вам сначала нужно заполнить ваше приложение некоторыми данными давайте создадим пример класса под названием профиль профиль , который имитирует класс профиля в социальной сети, используя имена известных людей и следующие поля строковый тип тип даты тип числа (целое число) тип массива (массив строк) тип массива (массив чисел) тип 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!'); после выполнения этого кода у вас теперь должен быть профиль профиль класс в вашей базе данных с созданными шестью объектами ваш новый класс должен выглядеть так теперь давайте рассмотрим примеры из каждого parsequery parsequery метода, вместе с краткими объяснениями того, что они делают пожалуйста, обратите внимание, что некоторые методы в этом списке могут принимать опции опции в качестве дополнительного аргумента, но в большинстве случаев это связано только с 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 и даже связана между двумя или более ограничениями сортировки это 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 } запросы geopoint это методы, специфичные для запросов geopoint это 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