Android
Data objects
Guía Técnica: Consultas Parse en Aplicaciones Android
23 min
recetario de consultas de parse en android introducción ya hemos visto cómo un parsequery parsequery con get get puede recuperar un solo parsequery parsequery de back4app hay muchas otras formas de recuperar datos con parsequery parsequery puedes recuperar muchos objetos a la vez, usar condiciones en los objetos que deseas recuperar, y más en esta guía, profundizarás en la parsequery parsequery clase y verás todos los métodos que puedes usar para construir tus consultas utilizarás una clase de base de datos simple con algunos datos simulados para realizar las consultas utilizando la consola de javascript en back4app puedes usar la consola de javascript en back4app para crear datos simulados fácilmente, o puedes crear tus datos con tu propia aplicación de android siguiendo esta guía este tutorial utiliza una aplicación creada en android studio 4 1 1 con buildtoolsversion=30 0 2 buildtoolsversion=30 0 2 , compile sdk version = 30 0 2 compile sdk version = 30 0 2 y targetsdkversion=30 targetsdkversion=30 en cualquier momento, puedes acceder al proyecto completo de android construido con este tutorial en nuestros repositorios de github repositorio de ejemplo en kotlin repositorio de ejemplo en java requisitos previos para completar este tutorial, necesitamos android studio una aplicación creada en back4app nota sigue el tutorial de nueva aplicación parse para aprender cómo crear una aplicación parse en back4app una aplicación de android conectada a back4app nota sigue el tutorial de instalación del sdk de parse para crear un proyecto de android studio conectado a back4app un dispositivo (o dispositivo virtual ) que ejecute android 4 1 (jelly bean) o superior objetivo explora la parsequery parsequery clase, diferentes métodos y aprende sobre los tipos de consultas que puedes crear en android la clase parsequery cualquier operación de consulta en parse utiliza el parsequery parsequery tipo de objeto, que te ayudará a recuperar datos específicos de tu back4app a lo largo de tu aplicación para crear un nuevo parsequery parsequery , necesitas pasar como parámetro la parsequery parsequery subclase deseada, que es la que contendrá los resultados de tu consulta es crucial saber que un parsequery parsequery solo se resolverá después de llamar a un método de recuperación (como parsequery find parsequery find o parsequery get parsequery get ), por lo que se puede configurar una consulta y encadenar varios modificadores antes de ser realmente llamada puedes leer más sobre la parsequery parsequery clase aquí en la documentación oficial https //parseplatform org/parse sdk android/api/ usando la consola js en back4app dentro del panel de control de tu aplicación back4app, encontrarás una consola api muy útil en la que puedes ejecutar código javascript directamente en esta guía usarás para almacenar y consultar objetos de datos de back4app en el panel principal de tu aplicación ve a core >api console >js console core >api console >js console guarda tus objetos de datos para ejecutar las consultas en esta guía primero necesitarás poblar tu aplicación con algunos datos vamos a crear una clase de muestra llamada perfil perfil , que simula una clase de perfil de redes sociales utilizando nombres de personas famosas y los siguientes campos tipo de cadena tipo de fecha tipo de número (entero) tipo de arreglo (arreglo de cadenas) tipo de arreglo (arreglo de números) tipo geopoint tipo de puntero anulable aquí está el parse object parse object código de creación de clases, así que adelante y ejecútalo en tu consola de 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!'); después de ejecutar este código, ahora deberías tener una perfil perfil clase en tu base de datos con seis objetos creados tu nueva clase debería verse así ahora echemos un vistazo a ejemplos de cada parsequery parsequery método, junto con breves explicaciones sobre lo que hacen ten en cuenta que algunos métodos en esta lista pueden tomar opciones opciones como un argumento adicional, pero en la mayoría de los casos, solo se relaciona con el masterkey masterkey y no es relevante para el contenido de esta guía, por lo que esta posibilidad se omitirá siempre que no sea relevante recuperadores de consultas estos métodos son responsables de ejecutar la consulta y recuperar sus resultados, estando siempre presentes en la implementación de su consulta este es el java métodos 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 } este es el kotlin métodos 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 } condiciones de consulta estos métodos te dan la posibilidad de aplicar restricciones condicionales a tu consulta, que son, sin duda, las operaciones más importantes en la consulta recuerda que todas estas operaciones se pueden encadenar antes de que se recuperen los resultados, por lo que se pueden lograr muchas combinaciones para satisfacer tus necesidades de consulta estos son java métodos 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 }); estos son kotlin métodos 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 } estos son java métodos 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 }); estos son kotlin métodos 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 } estos son java métodos 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 }); estos son kotlin métodos 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 } orden de consulta esencial en la mayoría de las consultas, el ordenamiento se puede lograr fácilmente en parse e incluso encadenar entre dos o más restricciones de ordenamiento estos son java métodos 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 }); estos son kotlin métodos 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 } selección de campos estos métodos afectan qué valores de campo pueden estar en los resultados de tu consulta estos son java métodos 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 }); estos son kotlin métodos 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 } consulta de geopuntos estos son métodos específicos para la consulta de geopoint estos son java métodos 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 }); estos son kotlin métodos 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 } paginación estos métodos están relacionados con utilidades de paginación, útiles para consultas que recuperarán un gran número de resultados estos son java métodos 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 }); estos son kotlin métodos 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 } almacenamiento local estos métodos permiten seleccionar la fuente de las consultas y utilizar un almacenamiento local estos son java métodos 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 }); estos son métodos 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 } conclusión al final de esta guía, aprendiste cómo usar diferentes tipos de consultas en android