Android
Data objects
Livre de recettes ParseQuery pour Android développeurs
23 min
livre de recettes de requêtes parse en android introduction nous avons déjà vu comment un parsequery parsequery avec get get peut récupérer un seul parsequery parsequery de back4app il existe de nombreuses autres façons de récupérer des données avec parsequery parsequery vous pouvez récupérer plusieurs objets à la fois, utiliser des conditions sur les objets que vous souhaitez récupérer, et plus encore dans ce guide, vous plongerez profondément dans la parsequery parsequery classe et verrez toutes les méthodes que vous pouvez utiliser pour construire vos requêtes vous utiliserez une classe de base de données simple avec des données simulées pour effectuer les requêtes en utilisant la console javascript sur back4app vous pouvez utiliser la console javascript sur back4app pour créer facilement des données simulées, ou vous pouvez créer vos données avec votre propre application android en suivant ce guide ce tutoriel utilise une application créée dans android studio 4 1 1 avec buildtoolsversion=30 0 2 buildtoolsversion=30 0 2 , compile sdk version = 30 0 2 compile sdk version = 30 0 2 et targetsdkversion=30 targetsdkversion=30 à tout moment, vous pouvez accéder au projet android complet construit avec ce tutoriel sur nos dépôts github dépôt d'exemple kotlin dépôt d'exemple java prérequis pour compléter ce tutoriel, nous avons besoin de android studio une application créée sur back4app remarque suivez le tutoriel de nouvelle application parse pour apprendre à créer une application parse sur back4app une application android connectée à back4app remarque suivez le tutoriel d'installation du sdk parse pour créer un projet android studio connecté à back4app un appareil (ou appareil virtuel ) fonctionnant sous android 4 1 (jelly bean) ou version ultérieure objectif explorez la classe parsequery classe parsequery et ses différentes méthodes et apprenez les types de requêtes que vous pouvez créer sur android la classe parsequery toute opération de requête sur parse utilise le parsequery parsequery type d'objet, qui vous aidera à récupérer des données spécifiques de votre back4app tout au long de votre application pour créer un nouveau parsequery parsequery , vous devez passer en paramètre la parsequery parsequery sous classe souhaitée, qui est celle qui contiendra les résultats de votre requête il est crucial de savoir qu'un parsequery parsequery ne sera résolu qu'après avoir appelé une méthode de récupération (comme parsequery find parsequery find ou parsequery get parsequery get ), donc une requête peut être configurée et plusieurs modificateurs peuvent être chaînés avant d'être réellement appelés vous pouvez en savoir plus sur la parsequery parsequery classe ici dans la documentation officielle https //parseplatform org/parse sdk android/api/ utiliser la console js sur back4app dans le tableau de bord de votre application back4app, vous trouverez une console api très utile dans laquelle vous pouvez exécuter du code javascript directement dans ce guide, vous l'utiliserez pour stocker et interroger des objets de données de back4app sur le tableau de bord principal de votre application, allez à core >api console >js console core >api console >js console enregistrez vos objets de données pour exécuter les requêtes dans ce guide, vous devrez d'abord peupler votre application avec des données créons une classe d'exemple appelée profile profile , qui simule une classe de profil de réseau social en utilisant des noms de personnes célèbres et les champs suivants type de chaîne type de date type de nombre (entier) type de tableau (tableau de chaînes) type de tableau (tableau de nombres) type geopoint type de pointeur nullable voici le parse object parse object code de création des classes, alors allez y et exécutez le dans votre console 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!'); après avoir exécuté ce code, vous devriez maintenant avoir une profile profile classe dans votre base de données avec six objets créés votre nouvelle classe devrait ressembler à ceci examinons maintenant des exemples de chaque parsequery parsequery méthode, accompagnés de brèves explications sur ce qu'elles font veuillez noter que certaines méthodes de cette liste peuvent prendre options options comme argument supplémentaire, mais dans la plupart des cas, cela ne concerne que l'utilisation de masterkey masterkey et n'est pas pertinent pour le contenu de ce guide, donc cette possibilité sera omise chaque fois qu'elle n'est pas pertinente récupérateurs de requêtes ces méthodes sont responsables de l'exécution de la requête et de la récupération de ses résultats, étant toujours présentes dans votre implémentation de requête ceci est les java méthodes 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 } ceci est les kotlin méthodes 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 } conditions de requête ces méthodes vous donnent la possibilité d'appliquer des contraintes conditionnelles à votre requête, qui sont sans doute les opérations les plus importantes dans la requête n'oubliez pas que ces opérations peuvent toutes être enchaînées avant que les résultats ne soient récupérés, donc de nombreuses combinaisons peuvent être réalisées pour répondre à vos besoins de requête ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } ordre des requêtes essentiel dans la plupart des requêtes, le tri peut être facilement réalisé dans parse et même enchaîné entre deux ou plusieurs contraintes de tri ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } sélection de champ ces méthodes affectent les valeurs de champ qui peuvent être dans vos résultats de requête ce sont java méthodes 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 }); ce sont des méthodes 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 } interrogation de geopoint ce sont des méthodes spécifiques à l'interrogation de geopoint ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } pagination ces méthodes sont liées aux utilitaires de pagination, utiles pour les requêtes qui récupéreront un grand nombre de résultats ce sont java méthodes 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 }); ce sont kotlin méthodes 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 } base de données locale ces méthodes permettent de sélectionner la source des requêtes et d'utiliser une base de données locale ce sont java méthodes 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 }); ce sont des méthodes 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 } conclusion à la fin de ce guide, vous avez appris à utiliser différents types de requêtes dans android