{"id":12874,"date":"2022-03-14T10:23:48","date_gmt":"2022-03-14T17:23:48","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=12874"},"modified":"2025-06-13T19:26:33","modified_gmt":"2025-06-14T02:26:33","slug":"reuse-sql-queries-between-server-mobile-app-databases","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/es\/reuse-sql-queries-between-server-mobile-app-databases\/","title":{"rendered":"Reutilizaci\u00f3n de consultas SQL entre bases de datos de servidores y aplicaciones m\u00f3viles"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Como todos sabemos, el c\u00f3digo es caro de mantener: cuanto m\u00e1s complejo es el c\u00f3digo, mayor es el coste de su mantenimiento. Por eso, desde el principio de los tiempos, los desarrolladores de software han trabajado muy duro para lograr el objetivo de <\/span><b>reutilizaci\u00f3n del c\u00f3digo<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Couchbase Mobile 3.0 introdujo soporte para consultas SQL++. Como desarrollador, lo primero que se me ocurri\u00f3 fue compartir las consultas utilizadas en proyectos dirigidos tanto a aplicaciones de Couchbase Server como de Couchbase Mobile.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00bfEs una buena idea? Exploremos esa cuesti\u00f3n utilizando datos de muestra y una aplicaci\u00f3n m\u00f3vil de prueba de concepto.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Datos de la muestra<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Todo el c\u00f3digo de este art\u00edculo est\u00e1 disponible en <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\"><span style=\"font-weight: 400;\">GitHub<\/span><\/a><span style=\"font-weight: 400;\">. Ver el <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/README.md\"><i><span style=\"font-weight: 400;\">L\u00c9AME<\/span><\/i><\/a> <span style=\"font-weight: 400;\">para obtener informaci\u00f3n sobre c\u00f3mo configurar los proyectos en su ordenador.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Los datos de la muestra proceden del <\/span><a href=\"https:\/\/www.openstreetmap.org\/#map=5\/38.007\/-95.844\"><span style=\"font-weight: 400;\">OpenStreetMap<\/span><\/a><span style=\"font-weight: 400;\"> y tiene licencia bajo la <\/span><a href=\"https:\/\/wiki.osmfoundation.org\/wiki\/Terms_of_Use\"><span style=\"font-weight: 400;\">Open Data Commons Licencia de base de datos abierta (ODbL)<\/span><\/a><span style=\"font-weight: 400;\"> por la Fundaci\u00f3n OpenStreetMap.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">El conjunto de datos contiene todas las tiendas que venden helados en Estados Unidos. A continuaci\u00f3n se muestra un documento JSON de ejemplo:<\/span><\/p>\n<pre class=\"\">{\r\n \"type\": \"Feature\",\r\n \"id\": \"node\/472242349\",\r\n \"properties\": {\r\n \"addrCity\": \"Austin\",\r\n \"addrHousenumber\": \"4477\",\r\n \"addrPostcode\": \"78745\",\r\n \"addrState\": \"TX\",\r\n \"addrStreet\": \"South Lamar Boulevard\",\r\n \"addrUnit\": \"#790\",\r\n \"amenity\": \"ice_cream\",\r\n \"cuisine\": \"ice_cream\",\r\n \"name\": \"Amy's Ice Creams\",\r\n \"phone\": \"+1-512-891-0573\",\r\n \"id\": \"node\/472242349\"\r\n},\r\n  \"geometry\": {\r\n   \"type\": \"Point\",\r\n   \"coordinates\": [\r\n    -97.7998856,\r\n    30.230688\r\n  ]\r\n }\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Como puede ver, se trata de un conjunto de datos vers\u00e1til para realizar pruebas porque tiene propiedades incrustadas en los documentos.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Ejemplo de aplicaci\u00f3n m\u00f3vil<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">En <a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\">ejemplo de aplicaci\u00f3n m\u00f3vil<\/a> se escribi\u00f3 en <\/span><a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/\"><span style=\"font-weight: 400;\">SwiftUI<\/span><\/a><span style=\"font-weight: 400;\"> con <\/span><a href=\"https:\/\/developer.apple.com\/documentation\/combine\"><span style=\"font-weight: 400;\">Combine<\/span><\/a><span style=\"font-weight: 400;\"> y es una aplicaci\u00f3n para iOS\/macOS que muestra las distintas tiendas que venden helados en Estados Unidos. La aplicaci\u00f3n incluye un <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/prebuilt-database.html\"><span style=\"font-weight: 400;\">base de datos preconstruida<\/span><\/a><span style=\"font-weight: 400;\"> con los mismos documentos JSON ya importados en ella para mayor comodidad. Esta aplicaci\u00f3n m\u00f3vil utiliza la \u00faltima versi\u00f3n del <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/quickstart.html\"><span style=\"font-weight: 400;\">SDK de Couchbase Lite<\/span><\/a><span style=\"font-weight: 400;\">. Puedes abrir el proyecto en XCode desde el archivo del proyecto en la carpeta src para seguir el proceso.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Una simple comparaci\u00f3n de consultas<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Para empezar nuestras pruebas, podemos escribir una consulta sencilla, para Couchbase Server, que muestre todas las direcciones de las helader\u00edas y las ordene por el nombre de la tienda:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">SELECT id, properties.addrCity, properties.addrHousenumber, properties.addrPostcode, \r\nproperties.addrStreet, properties.addrState, properties.name \r\nFROM icecream \r\nWHERE properties.addrCity &lt;&gt; \"\" \r\nAND type = \"Feature\" \r\nORDER BY properties.name<\/pre>\n<p><span style=\"font-weight: 400;\">Esta consulta tiene un filtro que s\u00f3lo devuelve los documentos en los que el objeto de la propiedad <\/span><i><span style=\"font-weight: 400;\">direcci\u00f3nCiudad <\/span><\/i><span style=\"font-weight: 400;\">tiene un valor y donde el documento <\/span><i><span style=\"font-weight: 400;\">tipo<\/span><\/i><span style=\"font-weight: 400;\"> es igual a <\/span><i><span style=\"font-weight: 400;\">Caracter\u00edstica<\/span><\/i><span style=\"font-weight: 400;\">. Si se pregunta por qu\u00e9 tenemos la <\/span><i><span style=\"font-weight: 400;\">direcci\u00f3nCiudad<\/span><\/i><span style=\"font-weight: 400;\"> filtro, se debe a que en este conjunto de datos hay datos sucios o documentos sin nombre o falta informaci\u00f3n. Utilizando un <\/span><i><span style=\"font-weight: 400;\">tipo<\/span><\/i><span style=\"font-weight: 400;\"> es com\u00fan en las aplicaciones m\u00f3viles para filtrar diferentes tipos de documentos.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Podemos utilizar el <\/span><b>Editor de consultas<\/b><span style=\"font-weight: 400;\"> del servidor Couchbase<\/span> <a href=\"https:\/\/docs.couchbase.com\/server\/current\/manage\/manage-ui\/manage-ui.html\"><b>Consola web<\/b><\/a><span style=\"font-weight: 400;\"> para ejecutar esta consulta. Cuando lo ejecut\u00e9 en mi Macbook Pro M1 Max personal, el resultado lleg\u00f3 en 38,4 ms. Esta consulta utiliza el <\/span><i><span style=\"font-weight: 400;\">adv_properties_addrCity_type<\/span><\/i><span style=\"font-weight: 400;\"> que puede ver haciendo clic en el icono <\/span><b>Asesor de \u00edndices<\/b><span style=\"font-weight: 400;\"> bot\u00f3n.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Portar la consulta a Couchbase Lite<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Veamos ahora esta misma consulta ejecut\u00e1ndose en nuestra aplicaci\u00f3n m\u00f3vil. Para ver la aplicaci\u00f3n m\u00f3vil, puedes usar XCode para abrir el archivo <\/span><i><span style=\"font-weight: 400;\">IceCreamLocator.xcodeproj<\/span><\/i><span style=\"font-weight: 400;\"> situado en la carpeta <\/span><i><span style=\"font-weight: 400;\">src <\/span><\/i><span style=\"font-weight: 400;\">carpeta. Una vez abierta en Xcode, busque la carpeta <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L32\"><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><\/a><span style=\"font-weight: 400;\"> swift en la carpeta <\/span><i><span style=\"font-weight: 400;\">Shared\\Data<\/span><\/i><span style=\"font-weight: 400;\"> carpeta.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">En <\/span><i><span style=\"font-weight: 400;\">init <\/span><\/i><span style=\"font-weight: 400;\">activa el registro detallado de la base de datos para inspeccionar la informaci\u00f3n de la consulta. Usando el registro detallado, puedes revisar lo que est\u00e1 pasando dentro de Couchbase Lite, incluyendo el rendimiento de la consulta.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Revisemos la consulta simple de Couchbase Server y veamos c\u00f3mo funciona en Swift con el nuevo SQL++ Query API. La funci\u00f3n para la consulta simple se llama <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L101\"><i><span style=\"font-weight: 400;\">getListByTypeNombreOrdenCiudad<\/span><\/i><\/a><span style=\"font-weight: 400;\">y el c\u00f3digo se muestra a continuaci\u00f3n:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">  func getListByTypeCityOrderName() -&gt; Void {\r\n      do {\r\n        if let query = try _db?.createQuery(\"SELECT id, \r\nproperties.addrCity, properties.addrHousenumber, properties.addrPostcode, properties.addrStreet, \r\nproperties.addrState, properties.name FROM _ WHERE properties.addrCity &lt;&gt; \\\"\\\" AND \r\ntype = \\\"Feature\\\" ORDER BY properties.name\") {\r\n            var results: [IceCreamLocation] = []\r\n            let explain = try query.explain()\r\n            print (\"**EXPLAIN** \\(explain)\")\r\n            for result in try query.execute() {\r\n                if let data = result.toJSON().data(using: .utf8){\r\n                   let location = try \r\nJSONDecoder().decode(IceCreamLocation.self, from: data)\r\n                   results.append(location)\r\n             }\r\n           }\r\n           self.iceCreamLocationList.send(results)\r\n           self.iceCreamLocationList.send(completion: .finished)\r\n         }\r\n     } catch {\r\n         print(\"**Error**: \\(error)\")\r\n         self.iceCreamLocationList.send(completion: .failure(DbError.unknown))\r\n     }\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">Hay varias formas de hacer una consulta SQL++ en Swift. En este ejemplo, usamos la base de datos <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile.html\"><i><span style=\"font-weight: 400;\">createQuery<\/span><\/i><\/a> <span style=\"font-weight: 400;\">para crear la consulta. En Couchbase Lite, estoy usando el car\u00e1cter de subrayado (_) como nombre de la base de datos antes de la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">DESDE <\/span><\/i><span style=\"font-weight: 400;\">sentencia. Cambiar el nombre de la base de datos es uno de los cambios esperados para reutilizar las sentencias SQL++. Adem\u00e1s, para escapar de las comillas en la sentencia <\/span><i><span style=\"font-weight: 400;\">DONDE <\/span><\/i><span style=\"font-weight: 400;\">tuve que a\u00f1adir el car\u00e1cter de escape de cadena Swift (<\/span><i><span style=\"font-weight: 400;\">\\<\/span><\/i><span style=\"font-weight: 400;\">) antes de cada comilla.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para probar esta consulta en ejecuci\u00f3n, puede abrir el archivo <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/ViewModels\/IceCreamListViewModel.swift#L24\"><i><span style=\"font-weight: 400;\">IceCreamListViewModel<\/span><\/i><\/a> <span style=\"font-weight: 400;\">que se encuentra en el archivo <\/span><i><span style=\"font-weight: 400;\">VerModelos <\/span><\/i><span style=\"font-weight: 400;\">carpeta. Localice la carpeta <\/span><i><span style=\"font-weight: 400;\">init <\/span><\/i><span style=\"font-weight: 400;\">y descomente la primera l\u00ednea de ejemplo situada en la parte inferior de la funci\u00f3n que llama a la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">getListByTypeNombreOrdenCiudad<\/span><\/i><span style=\"font-weight: 400;\"> de la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">_repositorio <\/span><\/i><span style=\"font-weight: 400;\">variable:<\/span><\/p>\n<pre class=\"\"> \/\/first example\r\n_repository.getListByTypeCityOrderName()<\/pre>\n<p><span style=\"font-weight: 400;\">Ahora puedes utilizar Xcode para ejecutar la aplicaci\u00f3n en un simulador de iOS o en una aplicaci\u00f3n de macOS. A continuaci\u00f3n, abra la aplicaci\u00f3n <\/span><b>Consola de depuraci\u00f3n <\/b><span style=\"font-weight: 400;\">en Xcode haciendo clic en el bot\u00f3n <\/span><b>Mostrar depuraci\u00f3n <\/b><span style=\"font-weight: 400;\">en la esquina inferior derecha del editor de Xcode, como se muestra a continuaci\u00f3n.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12888\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/properties.png\" alt=\"\" width=\"858\" height=\"396\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties.png 858w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-300x138.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-768x354.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/properties-20x9.png 20w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">El registro detallado mostrar\u00e1 una gran cantidad de informaci\u00f3n de registro. Para ayudarle a encontrar la informaci\u00f3n correcta en los registros, utilice el cuadro de filtro situado debajo de la consola. Por ejemplo, introduzca el texto \"<\/span><i><span style=\"font-weight: 400;\">Informaci\u00f3n de consulta<\/span><\/i><span style=\"font-weight: 400;\">\" y luego pulsa la tecla intro de tu teclado para ver informaci\u00f3n sobre la consulta. La consola de depuraci\u00f3n filtrar\u00e1 los datos que devuelve Couchbase Lite.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">La inspecci\u00f3n de los registros le mostrar\u00e1 el <\/span><i><span style=\"font-weight: 400;\">Informaci\u00f3n de consulta<\/span><\/i><span style=\"font-weight: 400;\"> y el n\u00famero de documentos encontrados por la consulta, cu\u00e1ntos bytes y cu\u00e1nto tiempo tard\u00f3 la consulta. Recuerda que los n\u00fameros que est\u00e1s viendo proceden de un simulador, no de un dispositivo real. Para ajustar el rendimiento de las aplicaciones m\u00f3viles, debes utilizar las herramientas de Apple con un dispositivo real.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">La velocidad a la que se ejecuta esta consulta es impresionante. A\u00fan m\u00e1s impresionante, todav\u00eda no se ha creado ning\u00fan \u00edndice, as\u00ed que esta consulta se ejecuta sin \u00edndice y hace un escaneo de tabla, lo que significa que tiene que mirar en la base de datos cada documento para ver si cumple los requisitos de la consulta. Couchbase Lite no requiere \u00edndices y har\u00e1 escaneos de tabla si es necesario, mientras que Couchbase Server s\u00ed requiere \u00edndices porque los escaneos de tabla pueden matar el rendimiento de todo el cluster.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">En varios casos, a\u00f1adir \u00edndices puede mejorar significativamente el rendimiento de las consultas, as\u00ed que dejemos de ejecutar la aplicaci\u00f3n, a\u00f1adamos el \u00edndice adecuado y volvamos a comprobar el rendimiento.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Abra el <\/span><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><span style=\"font-weight: 400;\"> y localice el <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L84\"><i><span style=\"font-weight: 400;\">createIceCreamIndexes<\/span><\/i><\/a> <span style=\"font-weight: 400;\">funci\u00f3n. Descomente el primer bloque de c\u00f3digo para crear el primer \u00edndice de consulta:<\/span><\/p>\n<pre class=\"lang:default decode:true\">   let simpleIndex = ValueIndexConfiguration([\"properties.name\", \"properties.addrCity\", \"type\"])\r\n   try _db?.createIndex(simpleIndex, name: \"idx_location_type_city_name\")<\/pre>\n<p><span style=\"font-weight: 400;\">\u00bfC\u00f3mo comprobamos si la consulta ha utilizado el \u00edndice que hemos creado? En la ventana <\/span><i><span style=\"font-weight: 400;\">getListByTypeNombreOrdenCiudad<\/span><\/i><span style=\"font-weight: 400;\"> ver\u00e1s dos l\u00edneas que imprimen los resultados de la funci\u00f3n explain en la consola:<\/span><\/p>\n<pre class=\"\">let explain = try query.explain()\r\nprint (\"**EXPLAIN** \\(explain)\")<\/pre>\n<p><span style=\"font-weight: 400;\">La consulta <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html#using\"><span style=\"font-weight: 400;\">explique<\/span><\/a><span style=\"font-weight: 400;\"> ejecutar\u00e1 el equivalente de la funci\u00f3n SQLite <\/span><i><span style=\"font-weight: 400;\">EXPLICAR EL PLAN DE CONSULTA<\/span><\/i><span style=\"font-weight: 400;\"> y almacenar los resultados en una cadena que se env\u00eda a la consola mediante la funci\u00f3n print. Puede filtrar por <\/span><i><span style=\"font-weight: 400;\">TABLA DE EXPLORACI\u00d3N <\/span><\/i><span style=\"font-weight: 400;\">en tu consola de depuraci\u00f3n para encontrar los resultados. Cuando revises los resultados, aseg\u00farate de eliminar el filtro anterior de la ventana de la consola. Ahora vuelve a ejecutar la aplicaci\u00f3n y mira los registros para comprobar el cambio en el rendimiento.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12889\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantable.png\" alt=\"\" width=\"854\" height=\"485\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable.png 854w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-300x170.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-768x436.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantable-20x11.png 20w\" sizes=\"auto, (max-width: 854px) 100vw, 854px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Deber\u00eda ver el <\/span><i><span style=\"font-weight: 400;\">USO DEL \u00cdNDICE <\/span><\/i><span style=\"font-weight: 400;\">con el nombre del \u00edndice creado, lo que indica que la consulta utiliza el \u00edndice adecuado. Ten en cuenta que aunque los \u00edndices pueden ayudar a las consultas, tambi\u00e9n pueden ralentizar la inserci\u00f3n y actualizaci\u00f3n de documentos. Puedes encontrar m\u00e1s informaci\u00f3n sobre indexaci\u00f3n en el manual de Couchbase Lite <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/indexing.html\"><span style=\"font-weight: 400;\">documentaci\u00f3n<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Otra comparaci\u00f3n de consultas<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">En nuestra segunda comparaci\u00f3n, filtramos los resultados s\u00f3lo para mostrar las helader\u00edas del Estado de Georgia, ordenadas por Ciudad y Estado:<\/span><\/p>\n<pre class=\"\">SELECT id, properties.addrCity, properties.addHousenumber, properties.addrPostcode, \r\nproperties.addrStreet, properties.addrState, properties.name \r\nFROM icecream \r\nWHERE\r\nproperties.addrCity IS NOT NULL \r\nAND properties.addrState = 'GA'\r\nAND type = \"Feature\" \r\nORDER BY properties.name<\/pre>\n<p><span style=\"font-weight: 400;\">Esta consulta devuelve 15 documentos y utiliza una consulta diferente, ya que utilizamos la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">properties.addrState <\/span><\/i><span style=\"font-weight: 400;\">y <\/span><i><span style=\"font-weight: 400;\">propiedades.direcci\u00f3nCiudad<\/span><\/i><span style=\"font-weight: 400;\"> atributos en nuestro <\/span><i><span style=\"font-weight: 400;\">DONDE <\/span><\/i><span style=\"font-weight: 400;\">cl\u00e1usula.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tenga en cuenta que hemos cambiado la forma de comprobar el <\/span><i><span style=\"font-weight: 400;\">propiedades.direcci\u00f3nCiudad<\/span><\/i><span style=\"font-weight: 400;\"> y utilizar el atributo <\/span><i><span style=\"font-weight: 400;\">IS NOT NULL<\/span><\/i><span style=\"font-weight: 400;\"> ahora. Esto demuestra la flexibilidad del lenguaje SQL++ y c\u00f3mo los desarrolladores pueden utilizar diferentes sintaxis para obtener los mismos resultados.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12890\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/selectID.png\" alt=\"\" width=\"1600\" height=\"699\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID.png 1600w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-300x131.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1024x447.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-768x336.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1536x671.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-20x9.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/selectID-1320x577.png 1320w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Ahora, volvamos a nuestra aplicaci\u00f3n m\u00f3vil para ver las diferencias. La funci\u00f3n para nuestra segunda consulta se llama <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L122\"><i><span style=\"font-weight: 400;\">getListByStateGeorgia<\/span><\/i><\/a><span style=\"font-weight: 400;\">y el c\u00f3digo se muestra a continuaci\u00f3n:<\/span><\/p>\n<pre class=\"decode-attributes:false lang:default decode:true\">    func getListByStateGeorgia() -&gt; Void {\r\n        do {\r\n           if let query = try _db?.createQuery(\"SELECT id, properties.addrCity, \r\nproperties.addrHousenumber, properties.addrPostcode, properties.addrStreet, \r\nproperties.addrState, properties.name FROM _ WHERE properties.addrCity NOT NULL AND \r\nproperties.addrState = \\\"GA\\\" AND type=\\\"Feature\\\" ORDER BY properties.name\") {\r\n               var results: [IceCreamLocation] = []\r\n               let explain = try query.explain()\r\n               print (\"**EXPLAIN** \\(explain)\")\r\n               for result in try query.execute() {\r\n                   if let data = result.toJSON().data(using: .utf8){\r\n                      let location = try \r\nJSONDecoder().decode(IceCreamLocation.self, from: data)\r\n                      results.append(location)\r\n                 }\r\n              }\r\n              self.iceCreamLocationList.send(results)\r\n              self.iceCreamLocationList.send(completion: .finished)\r\n          }\r\n        } catch {\r\n            print(\"**Error**: \\(error)\")\r\n            self.iceCreamLocationList.send(completion: .failure(DbError.unknown))\r\n     }\r\n   }<\/pre>\n<p><span style=\"font-weight: 400;\">Para probar esta nueva consulta, puede abrir el archivo <\/span><i><span style=\"font-weight: 400;\">IceCreamListViewModel<\/span><\/i><span style=\"font-weight: 400;\">. Localice el <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/ViewModels\/IceCreamListViewModel.swift#L21\"><i><span style=\"font-weight: 400;\">init<\/span><\/i><\/a> <span style=\"font-weight: 400;\">y comentar la primera l\u00ednea de ejemplo situada al final de la funci\u00f3n que llama a la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">getListByTypeNombreOrdenCiudad <\/span><\/i><span style=\"font-weight: 400;\">de la funci\u00f3n <\/span><i><span style=\"font-weight: 400;\">_repositorio<\/span><\/i><span style=\"font-weight: 400;\"> y descomenta la l\u00ednea que llama a nuestra nueva funci\u00f3n:<\/span><\/p>\n<pre class=\"\">\/\/first example\r\n\/\/_repository.getListByTypeCityOrderName()\r\n\r\n\/\/second example\r\n_repository.getListByStateGeorgia()<\/pre>\n<p><span style=\"font-weight: 400;\">Puedes depurar la aplicaci\u00f3n usando Xcode y comprobar el \u00e1rea de depuraci\u00f3n. Muestra los mismos 15 documentos que fueron devueltos por la consulta ejecutada en Couchbase Server, pero volvemos a hacer un escaneo de tabla que no es el comportamiento que queremos-cambiamos la consulta, pero no creamos ning\u00fan \u00edndice nuevo todav\u00eda.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12891\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantableusetemp.png\" alt=\"\" width=\"856\" height=\"420\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp.png 856w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-300x147.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-768x377.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantableusetemp-20x10.png 20w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Para solucionarlo, podemos volver a la funci\u00f3n <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift\"><i><span style=\"font-weight: 400;\">IceCreamLocationRepository<\/span><\/i><\/a> <span style=\"font-weight: 400;\">y localice el <\/span><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\/blob\/main\/src\/Shared\/Data\/IceCreamLocationRepository.swift#L86\"><i><span style=\"font-weight: 400;\">createIceCreamIndexes<\/span><\/i><\/a> <span style=\"font-weight: 400;\">funci\u00f3n. Descomente el segundo bloque de c\u00f3digo para crear el segundo \u00edndice de consulta:<\/span><\/p>\n<pre class=\"\">        let secondIndex = \r\nValueIndexConfiguration([\"properties.name\",\"properties.addrCity\", \"type\", \"properties.addrState\"])\r\n        try _db?.createIndex(secondIndex, name: \"idx_location_type_city_state_name\")<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12892\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2022\/03\/scantablelocationtype.png\" alt=\"\" width=\"860\" height=\"426\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype.png 860w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-300x149.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-768x380.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/scantablelocationtype-20x10.png 20w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Descubrimos que pod\u00edamos reutilizar el c\u00f3digo en estas dos consultas m\u00e1s sencillas, pero tuvimos que a\u00f1adir los \u00edndices para evitar los escaneos de tabla.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Capturas con reutilizaci\u00f3n de consultas<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Couchbase Server y Couchbase Mobile no usan el mismo almacenamiento o motor de consultas. Por lo tanto, es posible que te encuentres con consultas de Couchbase Server que necesiten ligeras modificaciones para ser optimizadas para Couchbase Mobile.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para obtener m\u00e1s informaci\u00f3n sobre Couchbase Server, consulte la documentaci\u00f3n de la p\u00e1gina <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/cost-based-optimizer.html\"><span style=\"font-weight: 400;\">Optimizador basado en costes<\/span><\/a><span style=\"font-weight: 400;\"> que utiliza el motor de consultas. El portal Couchbase Developer tambi\u00e9n tiene un buen art\u00edculo sobre c\u00f3mo mejorar <\/span><a href=\"https:\/\/developer.couchbase.com\/tutorial-tuning-tips-and-advice\"><span style=\"font-weight: 400;\">rendimiento de la consulta<\/span><\/a><span style=\"font-weight: 400;\"> en Couchbase Server que pueden explicar por qu\u00e9 algunas consultas se escriben de una manera espec\u00edfica.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Recomiendo leer la documentaci\u00f3n de Couchbase Mobile sobre resoluci\u00f3n de problemas <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html\"><span style=\"font-weight: 400;\">consultas<\/span><\/a><span style=\"font-weight: 400;\"> ya que me ha ayudado a escribir consultas optimizadas y explica mejor la salida del plan de consultas de SQLite.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Resumen<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Como se muestra en nuestros ejemplos de c\u00f3digo con la versi\u00f3n 3.0 de Couchbase Mobile, es posible reutilizar c\u00f3digo SQL++ entre Server y Mobile. Sin embargo, es posible que tengas que modificar las consultas y los \u00edndices para obtener un rendimiento \u00f3ptimo. Por ello, recomiendo encarecidamente leer la excelente documentaci\u00f3n de <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile-server-diffs.html\"><span style=\"font-weight: 400;\">SQL++ para m\u00f3viles - Diferencias con SQL++ para servidor<\/span><\/a><span style=\"font-weight: 400;\"> y <\/span><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/query-n1ql-mobile.html\"><span style=\"font-weight: 400;\">Cadenas de consulta SQL<\/span><\/a><span style=\"font-weight: 400;\">. Contiene informaci\u00f3n valiosa sobre los cambios que podr\u00eda tener que hacer en sus consultas para utilizarlas en sus aplicaciones m\u00f3viles.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Estos son algunos de los principales recursos a los que se hace referencia en este art\u00edculo:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/github.com\/biozal\/cblite-swiftui-icecream-locations\"><span style=\"font-weight: 400;\">Ejemplos de c\u00f3digo de GitHub<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/www.openstreetmap.org\/#map=5\/38.007\/-95.844\"><span style=\"font-weight: 400;\">Proyecto OpenStreetMap<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/prebuilt-database.html\"><span style=\"font-weight: 400;\">Couchbase Mobile - Documentos de la base de datos preconstruida<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/quickstart.html\"><span style=\"font-weight: 400;\">Couchbase Lite en Swift - Documentaci\u00f3n de inicio r\u00e1pido<\/span><\/a><span style=\"font-weight: 400;\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/indexing.html\"><span style=\"font-weight: 400;\">Couchbase Lite - Indexaci\u00f3n de documentos<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/cost-based-optimizer.html\"><span style=\"font-weight: 400;\">Couchbase Server - Optimizador basado en costes docs<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/developer.couchbase.com\/tutorial-tuning-tips-and-advice\"><span style=\"font-weight: 400;\">Couchbase Server - Consejos y sugerencias de ajuste<\/span><\/a><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/docs.couchbase.com\/couchbase-lite\/current\/swift\/troubleshooting-queries.html\"><span style=\"font-weight: 400;\">Couchbase Mobile - Resoluci\u00f3n de problemas de consultas<\/span><\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>As we all know, code is expensive to maintain\u2014the more complex the code, the higher the cost of maintaining it. Therefore, since the beginning of time, software developers have worked very hard to achieve the goal of code reusability. Couchbase [&hellip;]<\/p>","protected":false},"author":77540,"featured_media":12893,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1814,1810,1816,1812],"tags":[9527],"ppma_author":[9539],"class_list":["post-12874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-application-design","category-couchbase-mobile","category-couchbase-server","category-n1ql-query","tag-mobile-3-0"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Reuse SQL Queries between Server &amp; Mobile App Databases - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/es\/reuse-sql-queries-between-server-mobile-app-databases\/\" \/>\n<meta property=\"og:locale\" content=\"es_MX\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reuse SQL Queries between Server &amp; Mobile App Databases\" \/>\n<meta property=\"og:description\" content=\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/es\/reuse-sql-queries-between-server-mobile-app-databases\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-14T17:23:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T02:26:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1440\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aaron LaBeau - Principal Software Engineer\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@biozal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aaron LaBeau - Principal Software Engineer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"},\"author\":{\"name\":\"Aaron LaBeau - Principal Software Engineer\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54\"},\"headline\":\"Reuse SQL Queries between Server &#038; Mobile App Databases\",\"datePublished\":\"2022-03-14T17:23:48+00:00\",\"dateModified\":\"2025-06-14T02:26:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"},\"wordCount\":1636,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"keywords\":[\"mobile 3.0\"],\"articleSection\":[\"Application Design\",\"Couchbase Mobile\",\"Couchbase Server\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\",\"name\":\"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"datePublished\":\"2022-03-14T17:23:48+00:00\",\"dateModified\":\"2025-06-14T02:26:33+00:00\",\"description\":\"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg\",\"width\":2560,\"height\":1440},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reuse SQL Queries between Server &#038; Mobile App Databases\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54\",\"name\":\"Aaron LaBeau - Principal Software Engineer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/343f246f1f6971ad0851b3d3b558afbb\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg\",\"caption\":\"Aaron LaBeau - Principal Software Engineer\"},\"description\":\"Aaron LaBeau is a Principal Software Engineer on the Developer Experience and Ecosystem team. He has over 29 years with substantial development experience in Objective-C, Swift, Kotlin, Java, C#, Javascript, and Typescript. You can find his GitHub profile at https:\/\/www.github.com\/biozal\/.\",\"sameAs\":[\"https:\/\/www.couchbase.com\",\"https:\/\/www.linkedin.com\/in\/aaron-labeau-b444747\/\",\"https:\/\/x.com\/biozal\",\"https:\/\/www.youtube.com\/channel\/UCXgF-JqwBRGSawXajr6plGg\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/es\/author\/biozal\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog","description":"Couchbase Mobile 3.0 introdujo soporte para consultas SQL++, aprende a reutilizar consultas SQL entre el servidor y las bases de datos de la aplicaci\u00f3n m\u00f3vil.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/es\/reuse-sql-queries-between-server-mobile-app-databases\/","og_locale":"es_MX","og_type":"article","og_title":"Reuse SQL Queries between Server & Mobile App Databases","og_description":"Couchbase Mobile 3.0 introduced support for SQL++ queries, learn how to reuse SQL queries between Server and Mobile App Databases.","og_url":"https:\/\/www.couchbase.com\/blog\/es\/reuse-sql-queries-between-server-mobile-app-databases\/","og_site_name":"The Couchbase Blog","article_published_time":"2022-03-14T17:23:48+00:00","article_modified_time":"2025-06-14T02:26:33+00:00","og_image":[{"width":2560,"height":1440,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","type":"image\/jpeg"}],"author":"Aaron LaBeau - Principal Software Engineer","twitter_card":"summary_large_image","twitter_creator":"@biozal","twitter_misc":{"Written by":"Aaron LaBeau - Principal Software Engineer","Est. reading time":"10 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"},"author":{"name":"Aaron LaBeau - Principal Software Engineer","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54"},"headline":"Reuse SQL Queries between Server &#038; Mobile App Databases","datePublished":"2022-03-14T17:23:48+00:00","dateModified":"2025-06-14T02:26:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"},"wordCount":1636,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","keywords":["mobile 3.0"],"articleSection":["Application Design","Couchbase Mobile","Couchbase Server","SQL++ \/ N1QL Query"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/","url":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/","name":"Reuse SQL Queries between Server & Mobile App Databases - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","datePublished":"2022-03-14T17:23:48+00:00","dateModified":"2025-06-14T02:26:33+00:00","description":"Couchbase Mobile 3.0 introdujo soporte para consultas SQL++, aprende a reutilizar consultas SQL entre el servidor y las bases de datos de la aplicaci\u00f3n m\u00f3vil.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/shutterstock_1013448550-scaled.jpg","width":2560,"height":1440},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/reuse-sql-queries-between-server-mobile-app-databases\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Reuse SQL Queries between Server &#038; Mobile App Databases"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"El blog de Couchbase","description":"Couchbase, la base de datos NoSQL","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"El blog de Couchbase","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/8a68fa58a5fc5d8bf29577e7dc003a54","name":"Aaron LaBeau - Ingeniero de software principal","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/343f246f1f6971ad0851b3d3b558afbb","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","caption":"Aaron LaBeau - Principal Software Engineer"},"description":"Aaron LaBeau is a Principal Software Engineer on the Developer Experience and Ecosystem team. He has over 29 years with substantial development experience in Objective-C, Swift, Kotlin, Java, C#, Javascript, and Typescript. You can find his GitHub profile at https:\/\/www.github.com\/biozal\/.","sameAs":["https:\/\/www.couchbase.com","https:\/\/www.linkedin.com\/in\/aaron-labeau-b444747\/","https:\/\/x.com\/biozal","https:\/\/www.youtube.com\/channel\/UCXgF-JqwBRGSawXajr6plGg"],"url":"https:\/\/www.couchbase.com\/blog\/es\/author\/biozal\/"}]}},"authors":[{"term_id":9539,"user_id":77540,"is_guest":0,"slug":"biozal","display_name":"Aaron LaBeau - Principal Software Engineer","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/09\/aaron-couchbase.jpg"},"author_category":"","last_name":"LaBeau - Principal Software Engineer","first_name":"Aaron","job_title":"","user_url":"https:\/\/www.couchbase.com","description":"Aaron LaBeau es Ingeniero de Software Principal en el equipo de Experiencia del Desarrollador y Ecosistema.  Tiene m\u00e1s de 29 a\u00f1os de experiencia en desarrollo en Objective-C, Swift, Kotlin, Java, C#, Javascript y Typescript.  Puedes encontrar su perfil de GitHub en https:\/\/www.github.com\/biozal\/."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/12874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/users\/77540"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/comments?post=12874"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/12874\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media\/12893"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media?parent=12874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/categories?post=12874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/tags?post=12874"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/ppma_author?post=12874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}